Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed
@canismarko

Description

@canismarko

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions