Skip to content

[Bug]: Axes.indicate_inset connectors affect constrained layout #23425

Closed
@QuLogic

Description

@QuLogic

Bug summary

When adding indicate_inset on constrained figures, the position of Axes changes from a figure without indicators. This can be worked around by manually setting the connectors out of layout.

Code for reproduction

import matplotlib.pyplot as plt

for i in range(2):
    fig, axs = plt.subplots(2, 1, constrained_layout=True)
    for ax in axs:
        ax.plot([1, 2, 3])
    axs[1].set_xlim(0.5, 1.5)

# Add inset indicators only on the second figure.
_, conns = axs[0].indicate_inset_zoom(axs[1])

plt.show()

Actual outcome

Without connectors:
Figure_1
With connectors:
Figure_2
There is now some extra space between the two vertically.

Expected outcome

If you add:

for con in conns:
    con.set_in_layout(False)

then the Axes as positioned the same as the original image:
Figure_3

Additional information

No response

Operating system

No response

Matplotlib Version

37ccdca

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

git checkout

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