Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

enter image description here

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?

How can I get it to be like this on the x axis 2015-11-22, 2015-11-23, 2015-11-24?

like image 606
spen123 Avatar asked Jul 28 '26 05:07

spen123


1 Answers

Result of code

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

like image 78
A.H Avatar answered Jul 29 '26 19:07

A.H



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!