Skip to content

ConnectionPatch across axes needs to be excluded from layout management #14907

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
canismarko opened this issue Jul 28, 2019 · 6 comments
Closed
Milestone

Comments

@canismarko
Copy link

Bug report

Bug summary

When adding a ConnectionPatch that spans multiple axes with constrained_layout=True, the layout becomes broken, with the axes getting shrunk considerably. This can be resolved by calling patch.set_in_layout(False) before adding the artist to the axes. It may be useful to include a note about this to the documentation for ConnectionPatch.

Thanks to ImportanceOfBeingErnest for helping me figure this out on stackoverflow: https://stackoverflow.com/questions/57237711/connectionpatch-breaks-constrained-layout-when-crossing-axes/57241978#57241978

Code for reproduction

I followed the example provided here, except that I changed line 4 to use a managed layout.

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(6, 3), constrained_layout=True)

Actual outcome

Running the code with constrained_layout produced the following figure:
image

However, if I add con.set_in_layout(False) before the ax2.add_artist(con) on line 26, it produces a nicely layed out figure:

image

Expected outcome

This is the expected figure with constrained_layout=False from the example:

image

Matplotlib version

  • Operating system: Linux, Gentoo 2.6
  • Matplotlib version: 3.1.1
  • Matplotlib backend: module://ipykernel.pylab.backend_inline
  • Python version: 3.6.7
  • Jupyter version (if applicable): 5.2.3
  • Other libraries:

Packages were installed in a conda environment from conda-forge channel.

@canismarko canismarko changed the title ConnectionPatch across axes with needs to be excluded from layout management ConnectionPatch across axes needs to be excluded from layout management Jul 28, 2019
@jklymak
Copy link
Member

jklymak commented Jul 28, 2019

Want to try a PR along those lines? Might also be worth looking at constrained layout tutorial and letting us know where this could be better explained. I think another solution to your issue would have been if you had made the connector a figure artist rather than an axes artist. Then the layout manager wouldn’t have considered the patch as something it needed to make room for.

@canismarko
Copy link
Author

Yeah that sounds great. It'll be my first PR to a major project so feedback would be much appreciated once I get the PR done..

@jklymak
Copy link
Member

jklymak commented Jul 29, 2019

Yeah, its a bit of a process, and please ping us (and ping us) if it doesn't get attention.

@canismarko
Copy link
Author

I created a PR that addresses this in the documentation: #14957

If I don't see any movement in the next few days I'll ping the mailing list?

@jklymak
Copy link
Member

jklymak commented Aug 1, 2019

You can ping in the pr

ImportanceOfBeingErnest pushed a commit that referenced this issue Aug 14, 2019
#14957)

* Documentation for using ConnectionPatch across Axes with constrained_layout.

When using a figure with contrained layout management, adding a
ConnectionPatch between different subplot Axes breaks the layout. The
artist should be removed from layout considerations before being added
to the axes. This commit notes this fix in the documentation.

#14907

* Made documentation more general for artist limitations in constrained_layout.

* Revised the ConnectionPatch documentation to suggest Figure.add_artist().
@ImportanceOfBeingErnest
Copy link
Member

Closing as mainly fixed by #14957

@QuLogic QuLogic added this to the v3.2.0 milestone Aug 24, 2019
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

No branches or pull requests

4 participants