3

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?

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

I still get no labels on x axis
Not sure if this makes a difference but when I do print dates I get this [datetime.date(2015, 11, 22), datetime.date(2015, 11, 23), datetime.date(2015, 11, 24)] like in the question and when i do print dates[0] I get 2015-11-22
No, it's normal, stringification of datetime.date is what you have when you try to print a date with the print function. Try to remove rotation from xticks. Don't forget to close open pdf files (to correct handle rewrite of it) I know it's not a answer, but code works here ;) Try to copy/paste my code just to see. Try to do a plt.show() instead of plt.savefig() to see quickly the result. Never forget to close windows...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.