Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #93358
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Peter Pearson <pkpearson@nowhere.invalid> |
| Newsgroups | comp.lang.python |
| Subject | Re: Matplotlib X-axis timezone trouble |
| Date | 1 Jul 2015 05:50:17 GMT |
| Lines | 72 |
| Message-ID | <cvhdcpFdnliU1@mid.individual.net> (permalink) |
| References | <cve7ppFk1viU1@mid.individual.net> |
| X-Trace | individual.net Bj/iXdN4omXcXIYZHWw3yw4eXihSb71slsAW47mIftpHlcrm2k |
| Cancel-Lock | sha1:Mm+P9xOC8XBJKJVbT7Xa4WYbqNo= |
| User-Agent | slrn/pre1.0.0-18 (Linux) |
| Xref | csiph.com comp.lang.python:93358 |
Show key headers only | View raw
On 30 Jun 2015 00:56:26 GMT, Peter Pearson <pkpearson@nowhere.invalid> wrote:
> 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)?
Progress report:
I might be wrong in blaming the axis formatting. It looks as if the
datetimes themselves are being created wrong.
https://docs.python.org/2/library/datetime.html gives an
example like this:
>>> # Daylight Saving Time
>>> dt1 = datetime(2006, 11, 21, 16, 30, tzinfo=gmt1)
>>> dt1.dst()
datetime.timedelta(0)
>>> dt1.utcoffset()
datetime.timedelta(0, 3600)
>>> dt2 = datetime(2006, 6, 14, 13, 0, tzinfo=gmt1)
>>> dt2.dst()
datetime.timedelta(0, 3600)
>>> dt2.utcoffset()
datetime.timedelta(0, 7200)
... implying that adjustment for DST is made during the datetime constructor.
But look:
>>> from datetime import datetime
>>> import pytz
>>> pacific = pytz.timezone("US/Pacific")
>>> dt1 = datetime(2006, 11, 21, 16, 30, tzinfo=pacific) # no DST
>>> dt2 = datetime(2006, 6, 14, 13, 0, tzinfo=pacific) # yes DST
>>> dt1.dst()
datetime.timedelta(0)
>>> dt2.dst()
datetime.timedelta(0)
>>> dt1.utcoffset()
datetime.timedelta(-1, 57600)
>>> dt2.utcoffset()
datetime.timedelta(-1, 57600)
The dst() values are equal, and the utcoffset() values are equal, even
though one datetime is during DST and the other is not -- exactly the
opposite of the example.
The debugging tool pdb can't step into datetime.datetime(), so I'm
kinda stuck here.
--
To email me, substitute nowhere->runbox, invalid->com.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Matplotlib X-axis timezone trouble Peter Pearson <pkpearson@nowhere.invalid> - 2015-06-30 00:56 +0000
Re: Matplotlib X-axis timezone trouble Laura Creighton <lac@openend.se> - 2015-06-30 04:03 +0200
Re: Matplotlib X-axis timezone trouble Peter Pearson <pkpearson@nowhere.invalid> - 2015-06-30 04:57 +0000
Re: Matplotlib X-axis timezone trouble Chris Angelico <rosuav@gmail.com> - 2015-06-30 12:11 +1000
Re: Matplotlib X-axis timezone trouble Peter Pearson <pkpearson@nowhere.invalid> - 2015-06-30 04:49 +0000
Re: Matplotlib X-axis timezone trouble Chris Angelico <rosuav@gmail.com> - 2015-06-30 17:01 +1000
Re: Matplotlib X-axis timezone trouble Peter Pearson <pkpearson@nowhere.invalid> - 2015-06-30 16:42 +0000
Re: Matplotlib X-axis timezone trouble Chris Angelico <rosuav@gmail.com> - 2015-07-01 02:55 +1000
Re: Matplotlib X-axis timezone trouble Peter Pearson <pkpearson@nowhere.invalid> - 2015-07-01 05:50 +0000
Re: Matplotlib X-axis timezone trouble Chris Angelico <rosuav@gmail.com> - 2015-07-01 17:15 +1000
Datetime timezone trouble (was: Matplotlib X-axis timezone trouble) Peter Pearson <pkpearson@nowhere.invalid> - 2015-07-01 16:36 +0000
Re: Datetime timezone trouble (was: Matplotlib X-axis timezone trouble) Ian Kelly <ian.g.kelly@gmail.com> - 2015-07-01 10:55 -0600
Re: Datetime timezone trouble (was: Matplotlib X-axis timezone trouble) Peter Pearson <pkpearson@nowhere.invalid> - 2015-07-01 19:09 +0000
Re: Datetime timezone trouble (was: Matplotlib X-axis timezone trouble) Chris Angelico <rosuav@gmail.com> - 2015-07-02 03:08 +1000
Re: Matplotlib X-axis timezone trouble Akira Li <4kir4.1i@gmail.com> - 2015-07-04 07:29 +0300
Re: Matplotlib X-axis timezone trouble [SOLVED] Peter Pearson <pkpearson@nowhere.invalid> - 2015-07-04 17:37 +0000
Re: Matplotlib X-axis timezone trouble Tony the Tiger <tony@tiger.invalid> - 2015-07-09 19:50 +0000
Re: Matplotlib X-axis timezone trouble Peter Pearson <pkpearson@nowhere.invalid> - 2015-07-10 16:15 +0000
csiph-web