Matplotlib xaxis不显示

2024-09-29 21:27:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在测试python的matplotlib函数,结果发现x轴标签从绘图中消失了。在

我正在尝试下面这个Youtube中所示的示例: enter image description here

在本例中,x轴表示绘图的年份。 当我试着在我自己的Jupyter笔记本上做这件事时,我得到的是:

代码:

yearly_average[-20:].plot(x='year', y='rating', figsize=(15,10), grid=True)

enter image description here

我怎么解决这个问题?在


Tags: 函数代码绘图示例plotyoutubematplotlib笔记本
1条回答
网友
1楼 · 发布于 2024-09-29 21:27:49

让我们将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')

enter image description here

现在,让我们把“年”设为str,再测试一次。在

^{pr2}$

缺少标签

enter image description here

相关问题 更多 >

    热门问题