简体   繁体   English

plt.plot:在 Python 中绘制线时出现 X 轴问题

[英]plt.plot: X axis problem when plotting line in Python

i encounter a problem when plotting the graph in Python using plt.使用 plt 在 Python 中绘制图形时遇到问题。

The X axis value didnt match the index value at all and start from zero, i would like the x axis show 2009-03/2009-04 etc instead of starting from zero. X 轴值根本不匹配索引值并从零开始,我希望 x 轴显示 2009-03/2009-04 等,而不是从零开始。

Here is my data table这是我的数据表

在此处输入图像描述 在此处输入图像描述

plt.figure()

plt.plot(WTS_summary.values,linewidth=1,alpha = 0.7,c='salmon')
plt.xlabel("X-Axis")
plt.ylabel("Y-Axis")

The plot looks like this plot 看起来像这样

在此处输入图像描述

Thanks a lot...i had been stack on this for a long time even i try other plotting method非常感谢……即使我尝试了其他绘图方法,我也已经在这方面积累了很长时间

After suggestion it still show Error.建议后它仍然显示错误。 Thank You Himalaya Bir Shrestha谢谢喜马拉雅 Bir Shrestha

在此处输入图像描述

Can you add following line:您可以添加以下行:

plt.xticks(ticks=np.arange(0,len(WTS_summary)), labels=WTS_summary.index))

You need to import numpy first for it.您需要先导入 numpy 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM