简体   繁体   English

在Matplotlib上显示x轴 - Python

[英]Show x-axis on Matplotlib - Python

I have two arrays that i am graphing like this 我有两个阵列,我正在这样绘制

dates = [datetime.date(2015, 11, 22), datetime.date(2015, 11, 23), datetime.date(2015, 11, 24)]
points = [3L, 1L, 2L]

And then I plot like this 然后我就是这样画的

plt.plot(dates, points, 'r-o')
plt.xticks(rotation=70)
plt.tight_layout()
plt.savefig('test.pdf')

Which produces a graph like this 这会产生这样的图形

在此输入图像描述

But i don't want the times to appear, I want to dates to appear and I have an array of dates, not date times or times, so what is the x axis showing times? 但我不希望时间出现,我想要出现日期,我有一个日期数组,而不是日期时间或时间,那么显示时间的x轴是什么?

How can I get it to be like this on the x axis 2015-11-22, 2015-11-23, 2015-11-24 ? 我怎样才能在x轴2015-11-22, 2015-11-23, 2015-11-24得到它?

代码结果

Try this : 试试这个 :

dates = [datetime.date(2015, 11, 22), datetime.date(2015, 11, 23), datetime.date(2015, 11, 24)]
points = [3L, 1L, 2L]
x = [x for x in range(0,len(points))]
plt.plot(points, 'r-o')
plt.xticks(rotation=70)
plt.xticks(x,dates)
plt.tight_layout()
plt.savefig('test.pdf')

I hope it's help 我希望它有所帮助

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

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