Skip to content

FIX: move twins when moving parents#22817

Draft
jklymak wants to merge 1 commit intomatplotlib:mainfrom
jklymak:fix-moved-twin
Draft

FIX: move twins when moving parents#22817
jklymak wants to merge 1 commit intomatplotlib:mainfrom
jklymak:fix-moved-twin

Conversation

@jklymak
Copy link
Copy Markdown
Member

@jklymak jklymak commented Apr 10, 2022

PR Summary

Closes #21409, #21413 (which it replaces)

The original complaint was that

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.set_position([0.2,0.2,0.5,0.5])
ax2 = ax.twinx()
plt.show()

didn't properly position the twin. This will still be a problem with this PR, however

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax2 = ax.twinx()
ax.set_position([0.2,0.2,0.5,0.5])
plt.show()

works fine (whereas it did not before). I think this is probably acceptable.

Why we can't make it more flexible is that _make_twin is different for AxesSubplot versus Axes objects. AxesSubplot twins take the SubplotSpec of the sibling, where as Axes twins are "located" with their sibling.

The root of the problem here, in my opinion, is that twins are "siblings" versus children. If the twin was a child, it would just follow its parent around, but that is not how the code base with a Grouper treats them, and hence its not possible to tell which is the parent after the axes have been created.

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@anntzer
Copy link
Copy Markdown
Contributor

anntzer commented Apr 10, 2022

Perhaps discuss #21413 (comment) first?

@jklymak jklymak marked this pull request as draft April 10, 2022 10:24
@jklymak
Copy link
Copy Markdown
Member Author

jklymak commented Apr 10, 2022

Yes, sorry, meant to make this draft....

@matkoniecz
Copy link
Copy Markdown

Is #21413 (comment) resolved?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: twinx and twiny ignores previous set_position

3 participants