pytrends中的 Pyplot没有正确绘制



我目前正在尝试使用pytrends和pyplot绘制一个简单的搜索趋势。这个代码确实显示了一个图形和正确的线;然而,它也出现了第二行,我不确定它来自哪里。如图所示,正确的线是蓝色的,额外的线在底部是橙色的。我的代码如下:

from pytrends.request import TrendReq
from matplotlib import  pyplot as plt
pytrends = TrendReq(hl='en')
trend = pytrends.build_payload(['tesla'])
interest = pytrends.interest_over_time()
plt.plot(interest)
plt.grid()
plt.title('Trend')
plt.ylabel('Value')
plt.xlabel('Date')
plt.show()

图显示这多出的一行是因为isPartial列,它根据给定月份的数据是否完整显示一个布尔值。添加行del interest['isPartial']将简单地解决问题,并在没有表示isPartial值的行的情况下显示此图。总的来说,代码如下所示:

from matplotlib import  pyplot as plt
pytrends = TrendReq(hl='en')
trend = pytrends.build_payload(['tesla'])
interest = pytrends.interest_over_time()
del interest['isPartial']
plt.plot(interest)
plt.grid()
plt.title('Trend')
plt.ylabel('Value')
plt.xlabel('Date')
plt.show()

最新更新