我试图用谷歌趋势兴趣绘制一张股价图,但我无法将它们绘制在错误显示的同一张图中:
ValueError: x and y must have same first dimension, but have shapes (2094,) and (261,)
这就是我所拥有的:
import pandas_datareader.data as web
import pandas as pd
import matplotlib.pyplot as plt
from pytrends.request import TrendReq
pytrend = TrendReq()
plt.style.use('ggplot')
df = web.DataReader('ITUB4.SA', data_source='yahoo', start='2012-01-31', end='2020-07-21')
data = df.filter(['Close'])
print(df)
trend_list = ['ITUB4']
pytrend.build_payload(kw_list=['ITUB4'], geo='BR')
df_divo = pytrend.interest_over_time()
df_divo = df_divo.filter(['ITUB4'])
print(df_divo)
x = df.index
y1 = data['Close']
y2 = df_divo['ITUB4']
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
curve1 = ax1.plot(x, y1)
curve2 = ax2.plot(x, y2)
plt.plot()
plt.show()
提前谢谢
x
和y1
都来自df
,有2094行。但是,y2
来自pytrend
,只有261行,这就是为什么要得到ValueError
李>df.index
绘制df_divo.ITUB4
李>相关问题 更多 >
编程相关推荐