-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
plot_date() ignores timezone in matplotlib version 2.0.0 #8072
Comments
For reference, this works fine if the two plots are on different axes, which is all #6091 tests for. The problem happens if two plots with different timezones are done on the same axis. |
What timezone would you expect the axes to be in if you pass in data with different timezones (which may be considered 'different units')? |
It seems natural enough to convert everything to the axis' tz? |
Is there any confirmation on whether this is going to be fixed in v3.0? |
I don't think there is a fix for this right now. OTOH, I suspect its not too hard to do. PR would be welcome... |
Actually, I take that back. The problem is that |
Thanks for providing this information. Looking forward to the fix! |
I agree that the documentation shouldn't claim that this works. Not sure how we indicate that a kwarg actually has no effect, but that we'd like it to someday... I wouldn't expect this in the forseable future, as it gets at the root of our units handling, which is currently not set up to change units on the fly. Safest is to convert all your datetime objects to one timezone and then plot. |
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help! |
Still seems to be an issue on current main, so I'll keep this open. |
Since plot_date is discouraged anyway, it’s unlikely that we’ll change behavior. I suggest we close this by better documenting, that tz is only used for axis_date, so affects the axis labeling, but does not directly imply the timezone of the data. |
I'm guessing this is still and issue with plain |
Ok, but then let’s rephrase this into a new issue using |
With v3.8.2 I have import pytz
import matplotlib.pyplot as plt
from datetime import datetime
time_index_berlin = [pytz.timezone('Europe/Berlin').localize(datetime(year=2015, month=11, day=27, hour=x)) for x in range(4)]
time_index_utc = [pytz.timezone('UTC').localize(datetime(year=2015, month=11, day=27, hour=x)) for x in range(4)]
fig, ax = plt.subplots()
ax.plot(time_index_berlin, [4]*4, label='Berlin')
ax.plot(time_index_utc, [3]*4, label='UTC')
ax.legend()
fig.autofmt_xdate()
plt.show() If I reverse the order of plotting: ax.plot(time_index_utc, [3]*4, label='UTC')
ax.plot(time_index_berlin, [4]*4, label='Berlin') So it seems we plot in whichever timezone came first. |
Which is reasonable. So, if I understand correctly, we don’t have an issue with pure |
Ah fair enough, sorry for not checking... if we're not fixing anything on |
I'm confused - are we saying |
Yet again, my bad for not actually checking... (as an aside, in the above plot #8072 (comment) I'm a bit confused, isn't Berlin one hour ahead of UTC, which means the lines are the wrong way round (Berlin should be one hour to the right of UTC instead of one hour to the left)??) |
Confirmed, Yes, Berlin is an hour ahead of UTC (in winter). So when it's midnight in Berlin, it's only 11pm UTC. So I think the plot is correct (note both lines start at midnight). |
matplotlib/lib/matplotlib/axes/_axes.py Lines 1820 to 1824 in 41d4149
This is the implementation of The consequences of this implementation are as follows:
The equivalent to passing the So, in the example, both plots are using Given the admonition that very explicitly states "Do not use this for |
I do wonder if we should go a step further and hard deprecate this method. Datetime with timezones are confusing enough without slightly different semantics. |
From the discussion at #18346, it seems the intention at the time had been to pre-deprecate |
I'm fine with deprecating now. We've even already announced that we we will do this in the admonition at https://matplotlib.org/devdocs/api/_as_gen/matplotlib.axes.Axes.plot_date.html#matplotlib.axes.Axes.plot_date |
Bug report
Bug summary
copy paste the code from #5575
Actual outcome
The text was updated successfully, but these errors were encountered: