Thursday, 12 September 2013

How to change axis limits for time in Matplotlib?

How to change axis limits for time in Matplotlib?

I have a data set stored in a Pandas dataframe object, and the first
column of the dataframe is a datetime type, which looks like this:
0 2013-09-09 10:35:42.640000
1 2013-09-09 10:35:42.660000
2 2013-09-09 10:35:42.680000
3 2013-09-09 10:35:42.700000
In another column, I have another column called eventno, and that one
looks like:
0 0
1 0
2 0
3 0
I am trying to create a scatter plot with Matplotlib, and once I have the
scatter plot ready, I would like to change the range in the date axis
(x-axis) to focus on certain times in the data. My problem is, I could not
find a way to change the range the data will be plotted over in the x
axis. I tried this below, but I get a Not implemented for this type error.
plt.figure(figsize=(13,7), dpi=200)
ax.set_xlim(['2013-09-09 10:35:00','2013-09-09 10:36:00'])
scatter(df2['datetime'][df.eventno<11],df2['eventno'][df.eventno<11])
If I comment out the ax.set.xlim line, I get the scatter plot, however
with some default x axis range, not even matching my dates.
Do I have to tell matplotlib that my data is of datetime type, as well? If
so, then how can I do it? Assuming this part is somehow accomplished, then
how can I change the range of my data to be plotted?
Thanks!
PS: I tried uploading the picture, but I got a "Framing not allowed"
error. Oh well... It just plots it from Jan 22 1970 to Jan 27 1970. No
clue how it comes up with that :)

No comments:

Post a Comment