在matplotlib中更频繁地设置x轴标签名称
我有一个类似的数据框架,
Time(DDHHMM) True AOG Predicted AOG
5184 28:0:0.0 4.0 4.697324
5185 28:0:5.0 10.0 0.366948
5186 28:0:10.0 6.0 6.158011
5187 28:0:15.0 9.0 8.388459
5188 28:0:20.0 24.0 23.883515
... ... ... ...
5759 29:23:55.0 8.0 8.124675
我试图使用以下代码绘制它们
dataframe.plot(x='Time(DDHHMM)', y=['True','Predicted'],kind="line", figsize=(14,7),marker='.',grid=True)
plt.title("true and predicted data (EB-WB)")
plt.xlabel('Time',labelpad=2)
plt.ylabel('AOG')
plt.legend(loc='best',fancybox=True)
plt.grid(True)
plt.xlim(0,288)
plt.ylim(0,80)
plt.show()
,并获取只有3个X轴值名称的位置。
但是,我想添加更多X轴值名,但在文档中找不到任何可行的东西。我尝试使用XTICKS(启动,结束,步骤)
,但没有更改任何内容。另外,我尝试了plot.locator_params(axis ='x',nbins = 20)
从stackoverflow问题之一中也无法正常工作。我该如何解决?
I have a dataframe like this
Time(DDHHMM) True AOG Predicted AOG
5184 28:0:0.0 4.0 4.697324
5185 28:0:5.0 10.0 0.366948
5186 28:0:10.0 6.0 6.158011
5187 28:0:15.0 9.0 8.388459
5188 28:0:20.0 24.0 23.883515
... ... ... ...
5759 29:23:55.0 8.0 8.124675
I am trying to plot them using following code
dataframe.plot(x='Time(DDHHMM)', y=['True','Predicted'],kind="line", figsize=(14,7),marker='.',grid=True)
plt.title("true and predicted data (EB-WB)")
plt.xlabel('Time',labelpad=2)
plt.ylabel('AOG')
plt.legend(loc='best',fancybox=True)
plt.grid(True)
plt.xlim(0,288)
plt.ylim(0,80)
plt.show()
And getting figure where there are only 3 x-axis value names.
However, I want to add more x-axis value names but did not find anything in the documentation that would work. I tried using xticks(start,end,step)
but it doesnt change anything. Also I tried plot.locator_params(axis='x', nbins=20)
from one of the stackoverflow issues which is not working too. How could I fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
plt.show()
之前,请尝试插入此代码:Before
plt.show()
, try inserting this code: