Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'url:sourceforge': 0.03; 'desired,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'explicitly': 0.15; 'instead.': 0.15; '1),': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'example.': 0.18; 'skip:` 10': 0.18; 'produces': 0.22; 'pass': 0.22; 'code,': 0.23; 'import': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; "doesn't": 0.28; 'directly,': 0.29; 'matplotlib': 0.29; 'code': 0.31; 'skip:d 20': 0.32; 'skip:p 30': 0.32; 'anybody': 0.32; 'problem': 0.33; 'pacific': 0.33; 'shift': 0.33; 'running': 0.34; 'message-id:@gmail.com': 0.35; 'to:addr:python-list': 0.35; 'but': 0.36; 'beginning': 0.36; 'subject:: ': 0.37; 'instead': 0.38; 'received:org': 0.38; 'skip:p 20': 0.38; 'method': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'subject:-': 0.39; 'why': 0.40; 'your': 0.60; '30,': 0.63; 'course': 0.64; 'received:89': 0.80; 'pacific,': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Akira Li <4kir4.1i@gmail.com> Subject: Re: Matplotlib X-axis timezone trouble Date: Sat, 04 Jul 2015 07:29:45 +0300 References: Mime-Version: 1.0 Content-Type: text/plain X-Gmane-NNTP-Posting-Host: 89.169.229.68 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:3BeHmiqixCe/XWqX1n4hk1PJyaU= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1435984224 news.xs4all.nl 2837 [2001:888:2000:d::a6]:34145 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93479 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)? > Your pytz usage is incorrect. Don't pass a pytz tzinfo object to the datetime construtor directly, use `.localize()` method instead. Read the note at the very beginning of pytz docs http://pytz.sourceforge.net/