-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Weird DatetimeIndex + secondary y axis plotting issue #18768
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
Comments
FYI: just upgraded to pandas 0.21.1 and issue still manifests itself |
Thanks for checking on the new release. Could you try dropping some breakpoints in pandas/pandas/plotting/_core.py Line 999 in 265e327
axes object, and I suspect that could be confusing things when you have a secondary y. Or maybe it's something else :)
|
Ok, this was quite a rabbit hole to debug, let's see if I can manage to write down what I found. Main reason that the lines in graph with primary and secondary axis do not properly cover the same x range, is the difference in conversion between:
Short description what is happening, starting with the same data as above: a = pd.Series([16, 13, 11], index=pd.to_datetime(['2017-09-13', '2017-09-14', '2017-09-16'], format='%Y-%m-%d'))
b = pd.Series([23, 27, 25], index=pd.to_datetime(['2017-09-13', '2017-09-14', '2017-09-15'], format='%Y-%m-%d')) First plot on primary axis:a.plot(ax=ax, style='o-', secondary_y=False) in pandas/pandas/plotting/_core.py Line 947 in 265e327
pandas.plotting._timeseries._use_dynamic_x the frequency variables freq (and ax_freq ) are None for ("irregular") series a .pandas/pandas/plotting/_timeseries.py Line 211 in 265e327
As a result of this a DatetimeConverter is set up as converter for the x axis .
Second plot on secondary axis:b.plot(ax=ax, style='o-', secondary_y=True) For the secondary axis twin axes is created.
Back in SummaryDuring plot of I guess there are several possible solutions (but my understanding of the inner workings of pandas and matplotlib are limited, so I don't really know the best way forward in terms of breaking things and keeping things managable):
I hope this sheds some light on what is happening here. (note that I didn't look into the case where both plots are done on the secondary axes, but I guess it is related) |
Has there been any progress on this issue at all? I have been struggling to find some solutions. |
I haven't had time to go through @soxofaan's (excellent) debugging yet. |
Is there any kind of workaround that can be used to disable the labels on either the primary or secondary plot so that we can can get what we want with the first dataset and then overlay the second without the labels disappearing? (I experimented with different formatters/locators without success) |
Today I stumbled on weird issue with plotting two series with a datetimeindex and a secondary axis.
Code that illustrates the problem:
b
is a straightforward time series with successive daysa
has a one day jump in the last itemMore in depth experimentation (and version information) can be found in the notebook at https://gist.github.com/soxofaan/9fdfdeafb8fb555dd8547bc48a27e2f3
(also notice the inconsistant x axes label formatting and orientation)
The text was updated successfully, but these errors were encountered: