【发布时间】:2020-11-12 09:37:19
【问题描述】:
我正在尝试绘制股票价格及其对 Google 趋势的兴趣的图表,但我无法将它们绘制在与错误所示相同的图表中:
ValueError: x 和 y 必须具有相同的第一维,但形状为 (2094,) 和 (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()
提前致谢!
【问题讨论】:
标签: python matplotlib