diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index 261dd50a730e..6d64961bd37f 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -4229,8 +4229,7 @@ def __init__(self, xyA, xyB, coordsA, coordsB=None, clip_on=False, dpi_cor=1., **kwargs): - """ - Connect point *xyA* in *coordsA* with point *xyB* in *coordsB* + """Connect point *xyA* in *coordsA* with point *xyB* in *coordsB* Valid keys are @@ -4273,6 +4272,22 @@ def __init__(self, xyA, xyB, coordsA, coordsB=None, Alternatively they can be set to any valid `~matplotlib.transforms.Transform`. + + .. note:: + + Using :class:`~matplotlib.patches.ConnectionPatch` across + two :class:`~matplotlib.axes.Axes` instances is not + directly compatible with :doc:`constrained layout + `. Add the + artist directly to the :class:`~matplotlib.figure.Figure` + instead of adding it to a specific Axes. + + .. code-block:: default + + fig, ax = plt.subplots(1, 2, constrained_layout=True) + con = ConnectionPatch(..., axesA=ax[0], axesB=ax[1]) + fig.add_artist(con) + """ if coordsB is None: coordsB = coordsA diff --git a/tutorials/intermediate/constrainedlayout_guide.py b/tutorials/intermediate/constrainedlayout_guide.py index be897b7bb6f1..57597a02d9f4 100644 --- a/tutorials/intermediate/constrainedlayout_guide.py +++ b/tutorials/intermediate/constrainedlayout_guide.py @@ -581,6 +581,13 @@ def docomplicated(suptitle=None): # # * There are small differences in how the backends handle rendering fonts, # so the results will not be pixel-identical. +# +# * An artist using axes coordinates that extend beyond the axes +# boundary will result in unusual layouts when added to an +# axes. This can be avoided by adding the artist directly to the +# :class:`~matplotlib.figure.Figure` using +# :meth:`~matplotlib.figure.Figure.add_artist`. See +# :class:`~matplotlib.patches.ConnectionPatch` for an example. ########################################################### # Debugging