-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: Fix missing tick labels on twinned axes #33767
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
BUG: Fix missing tick labels on twinned axes #33767
Conversation
Thanks for the PR and detailed explanation. Can we open an issue - and ref it in the test? |
I've opened #33819 which has screenshot images produced by running the example code with the problem and after the proposed fix has been applied. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ebardie !
4167f13
to
eef11a5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, @ebardie thanks for the PR, looks nice!
The part i think needs to improve is the testing. It is fine to test the internal function itself, but generally we want to test how users will see the difference from plotting api perspective. e.g. df.plot(blabla)
and then assert the axis labels change etc. Quite similar to what you have in your example in the issue.
Therefore, I would prefer to replace this internal function test with the example you have in the issue and test if axis label is changed etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping after you can address @charlesdong1991 comments
eef11a5
to
c96e671
Compare
c96e671
to
4c00f01
Compare
Hi @jreback . I've made changes that suit @charlesdong1991. Pinging as requested. |
nice! @ebardie not big deal at all: generally would be nicer to add issue number in tests so that they can easily be tracked in the future, but i think fine this way. could be a tip for your future PRs |
4c00f01
to
e1cd544
Compare
Easily remedied now, so I've done so. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test comment & pls add a note in plotting bug fixes for 1.1
e1cd544
to
701fd3f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looked ok
can u merge master and ping on green
cc @WillAyd @TomAugspurger
1822447
to
3fc8bee
Compare
I just tried merging master, as this looked ready, although |
0dea8eb
to
f1e6f03
Compare
@charlesdong1991 @MarcoGorelli : I have re-made changes against current master and your suggestions above. Built locally, and tested with the demonstration test case above, and against my specific use case (https://gitlab.com/eBardie/topplot). |
Thanks for updating and for your patience! @charlesdong1991 good to go? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MarcoGorelli I think it's good to go, but I requested the review from @jreback or @WillAyd for a further look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ebardie I am very sorry to block your PR again, just a minor comment when I came across your whatsnew
d3d840c
to
2de2ec9
Compare
This comment has been minimized.
This comment has been minimized.
@@ -331,6 +331,7 @@ Plotting | |||
|
|||
- Bug in :meth:`DataFrame.plot` was rotating xticklabels when ``subplots=True``, even if the x-axis wasn't an irregular time series (:issue:`29460`) | |||
- Bug in :meth:`DataFrame.plot` where a marker letter in the ``style`` keyword sometimes causes a ``ValueError`` (:issue:`21003`) | |||
- Twinned axes were losing their tick labels which should only happen to all but the last row or column of 'externally' shared axes (:issue:`33819`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is "externally" shared axes a standard term?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, hence the quotes. MPL overloading the term "axes" is problem:
Twinned axes were losing their tick labels which should only happen to all but the last row or column of axes shared between axes (:issue:33819
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should add that this is explained more thoroughly in the linked Issue #33819
2de2ec9
to
62a98a2
Compare
62a98a2
to
dcb133b
Compare
@WillAyd Okay, changes made as per your requests. Tested and builds on the CI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@TomAugspurger @jreback for any remaining comments |
thanks @ebardie and thanks for the patience, we have lots of PRs! |
\o/ and thanks. I espeically appreciate your appreciation of the understandable-but-frustrating delays :) My thanks to you all for keeping Pandas going and growing! |
Background:
Multi-row and/or multi-column subplots can utilize shared axes.
An external share happens at axis creation when a sharex or sharey
parameter is specified.
An internal share, or twinning, occurs when an overlayed axis is created
by the Axes.twinx() or Axes.twiny() calls.
The two types of sharing can be distinguished after the fact in the
following manner. If two axes sharing an axis also have the same
position, they are not in an external axis share, they are twinned.
For externally shared axes Pandas automatically removes tick labels for
all but the last row and/or first column in
./pandas/plotting/_matplotlib/tools.py's function _handle_shared_axes().
The problem:
_handle_shared_axes() should be interested in externally shared axes,
whether or not they are also twinned. It should, but doesn't, ignore
axes which are only twinned. Which means that twinned-only axes wrongly
lose their tick labels.
The cure:
This commit introduces has_externally_shared_axis() which identifies
externally shared axes and uses it to expand upon the existing use of
len(Axes.get_shared{x,y}_axes().get_siblings(a{x,y})) in
_handle_shared_axes() which miss these cases.
The demonstration test case:
Note especially the axis labels (and associated tick labels).
See images produced by this code for problem and fixed cases at the bug report: #33819.
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff