2024-09-29 21:27:49 发布
网友
我正在测试python的matplotlib函数,结果发现x轴标签从绘图中消失了。在
我正在尝试下面这个Youtube中所示的示例:
在本例中,x轴表示绘图的年份。 当我试着在我自己的Jupyter笔记本上做这件事时,我得到的是:
代码:
yearly_average[-20:].plot(x='year', y='rating', figsize=(15,10), grid=True)
我怎么解决这个问题?在
让我们将Year_average dataframe中的Year列从str或object dtype转换为integer。然后,利用大熊猫的情节。在
MVCE公司:
使用xaxis ticklabels的工作示例,其中dtype“Year”是整数
df = pd.DataFrame({'Year':[2000,2001,2002,2003,2004,2005],'Value':np.random.randint(1000,5000,6)}) df.plot('Year','Value')
现在,让我们把“年”设为str,再测试一次。在
缺少标签
让我们将Year_average dataframe中的Year列从str或object dtype转换为integer。然后,利用大熊猫的情节。在
MVCE公司:
使用xaxis ticklabels的工作示例,其中dtype“Year”是整数
现在,让我们把“年”设为str,再测试一次。在
^{pr2}$缺少标签
相关问题 更多 >
编程相关推荐