Skip to content

plot_date() ignores timezone #5575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
timtroendle opened this issue Nov 27, 2015 · 4 comments
Closed

plot_date() ignores timezone #5575

timtroendle opened this issue Nov 27, 2015 · 4 comments

Comments

@timtroendle
Copy link

Using matplotlib 1.5.0, I am doing the following:

import pytz
import matplotlib.pyplot as plt
from datetime import datetime
time_index = [pytz.timezone('Europe/Berlin').localize(datetime(year=2015, month=11, day=27, hour=x)) for x in range(4)]
plt.plot_date(time_index, [4]*4, tz='Europe/Berlin')
plt.plot_date(time_index, [4]*4, tz='UTC')

The two plot_date calls yield the same plot, hence it seems plot_date() ignores the tz argument. This had been reported and fixed in #193, but for me it doesn't seem to work.

@mdboom
Copy link
Member

mdboom commented Nov 27, 2015

Might be a dupe of #5543.

@brendene
Copy link

Fixing #5543 is a prerequisite to fixing this bug however there still exists another bug.

In matplotlib/axis.py update_units is called 3 times. First from _base.py:_xy_from_xy where the single parameter passed in is the time_index above. This sets Axis.units to 'Europe/Berlin'.

The second time is on the y-axis, ignore this one.

The third time is from the plot_date which calls xaxis_date. Since Axis.units was already set to 'Europe/Berlin', it will not be set to the 'UTC' which was passed in.

Calling self.set_units(default) regardless of whether or not Axis.units is None fixes the issue above but probably isn't the most efficient. I will continue reading through the code but I don't know it well enough yet to make a proper fix.

As for why there is also a dependency on #5543, making the above fix will fix it for the example above. However, a subsequent call to plot_date using tz='US/Eastern' will still plot in UTC.

tacaswell added a commit that referenced this issue Mar 13, 2016
FIX: plot_date ignores timezone

Closes #5575

Conflicts:
	lib/matplotlib/tests/test_axes.py

	   multiple PRs added tests at same location in file
	   keep all.
@QuLogic QuLogic added this to the 1.5.2 (Critical bug fix release) milestone Mar 13, 2016
tacaswell added a commit to tacaswell/matplotlib that referenced this issue May 22, 2016
FIX: plot_date ignores timezone

Closes matplotlib#5575

Conflicts:
	lib/matplotlib/tests/test_axes.py

	   multiple PRs added tests at same location in file
	   keep all.
@pjadzinsky
Copy link

Hi,

I just upgraded to 1.5.3 and I still see the same behavior as originaly described by timtroendle

@tacaswell
Copy link
Member

@pjadzinsky can you make a new issue for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants