I'm using matplotlib to plot data against timestamps in python 2.6. I've found the plot_date() function and it works great! However, the times are all in UTC. I read the docs which says you can pass the tz parameter to the function to set a custom timezome. This does not seem to be working. Even after passing the parameter, times remain in UTC. I've tried a few methods as well to no avail.
Notes: I'm importing a CSV file filled with epoch times to generate the X-axis. So, I'm converting from epoch to matplotlib format using epoch2num().
import matplotlib.pyplot as plt import matplotlib.mlab as mlab import matplotlib.dates as mdates from pytz import timezone ... dates = mdates.epoch2num(dates) # Converting my list of dates from epochs plt.plot_date(dates, data,fmt='-',tz="US/Eastern",xdate=True)
That code fails to produce correct timestamps along the axis. It graphs just fine though.
Same result as the first example. Everything remains in UTC.
For grins I ran a num2date() on the 'dates' list and printed the output. The values output were in UTC. I then added the tz=timezone('US/Eastern') to the num2date() call and the values output were in Eastern, as they should be.
I also tried to "preconvert" the dates to Eastern before calling plot_date, and then omitting the tz= keyword in plot_date, but still the values are UTC.
Finally, I edited my matplotlibrc file and changed #timezone UTC to #timezone US/Eastern and still no success.
What am I missing to get these dates to graph outside of UTC?
I uninstalled Matplotlib 1.0.0 and installed 0.99.3 instead. After doing this, I am now able to properly set the timezone and see the effects. I tested with the sample provided by Unutbu and then with my own code. Everything works as it should.
Perhaps this is a bug in 1.0.0 then?
I'm seeing this behavior in Matplotlib 1.0.1 too.
I looked at it in the debugger and IMHO the argument
tz is ignored. The bug is in
matplotlib.axes.Axes.xaxis_date (file "axes.py", line 2679).
I filed a bug report for it: https://sourceforge.net/tracker/index.php?func=detail&aid=3176823&group_id=80706&atid=560720