Matplotlib X-axis timezone trouble
Peter Pearson
pkpearson at nowhere.invalid
Tue Jun 30 00:57:11 EDT 2015
On Tue, 30 Jun 2015 04:03:57 +0200, Laura Creighton <lac at openend.se> wrote:
> In a message of 30 Jun 2015 00:56:26 +0000, Peter Pearson writes:
>>The following code produces a plot with a line running from (9:30, 0) to
>>(10:30, 1), not from (8:30, 0) to (9:30, 1) as I desire.
>>
>>If I use timezone None instead of pacific, the plot is as desired, but
>>of course that doesn't solve the general problem of which this is a
>>much-reduced example.
>>
>>If I use timezone US/Central, I get the same (bad) plot.
>>
>>import matplotlib.pyplot as plt
>>import datetime
>>import pytz
>>pacific = pytz.timezone("US/Pacific")
>>fig = plt.figure()
>>plt.plot([datetime.datetime(2014, 10, 7, 8, 30, tzinfo=pacific),
>> datetime.datetime(2014, 10, 7, 9, 30, tzinfo=pacific)],
>> [0,1], marker="o", color="green")
>>fig.autofmt_xdate()
>>plt.show()
>>
>>Does anybody know why this shift is occurring? Is Matplotlib
>>confused about what timezone to use in labeling the axis? How
>>would I tell it what timezone to use (preferably explicitly in
>>the code, not in matplotlibrc)?
[snip]
>
> I know that your problem is that all your times are in UTC, even
> though you do not want this. I had this too. I forget what I did.
Actually, UTC is very helpful in this project, which has to
deal with timestamped data from various timezones. After I finally
stumbled upon datetime's astimezone() method, things seemed to be
going smoothly . . .
> I do not know if this solution from stackoverflow.com will work for
> you -- it is definitely different from what I did, but that does
> not in any way make it wrong. Try and see? and report back?
>
> http://stackoverflow.com/questions/4485607/matplotlib-plot-date-keeping-times-in-utc-even-with-custom-timezone
Thanks for the pointer. I'll report back.
--
To email me, substitute nowhere->runbox, invalid->com.
More information about the Python-list
mailing list