Skip to content

Commit b34c605

Browse files
Mark WolfImportanceOfBeingErnest
authored andcommitted
Documentation for using ConnectionPatch across Axes with constrained_… (matplotlib#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. matplotlib#14907 * Made documentation more general for artist limitations in constrained_layout. * Revised the ConnectionPatch documentation to suggest Figure.add_artist().
1 parent 22d7689 commit b34c605

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/matplotlib/patches.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4215,8 +4215,7 @@ def __init__(self, xyA, xyB, coordsA, coordsB=None,
42154215
clip_on=False,
42164216
dpi_cor=1.,
42174217
**kwargs):
4218-
"""
4219-
Connect point *xyA* in *coordsA* with point *xyB* in *coordsB*
4218+
"""Connect point *xyA* in *coordsA* with point *xyB* in *coordsB*
42204219
42214220
Valid keys are
42224221
@@ -4259,6 +4258,22 @@ def __init__(self, xyA, xyB, coordsA, coordsB=None,
42594258
42604259
Alternatively they can be set to any valid
42614260
`~matplotlib.transforms.Transform`.
4261+
4262+
.. note::
4263+
4264+
Using :class:`~matplotlib.patches.ConnectionPatch` across
4265+
two :class:`~matplotlib.axes.Axes` instances is not
4266+
directly compatible with :doc:`constrained layout
4267+
</tutorials/intermediate/constrainedlayout_guide>`. Add the
4268+
artist directly to the :class:`~matplotlib.figure.Figure`
4269+
instead of adding it to a specific Axes.
4270+
4271+
.. code-block:: default
4272+
4273+
fig, ax = plt.subplots(1, 2, constrained_layout=True)
4274+
con = ConnectionPatch(..., axesA=ax[0], axesB=ax[1])
4275+
fig.add_artist(con)
4276+
42624277
"""
42634278
if coordsB is None:
42644279
coordsB = coordsA

tutorials/intermediate/constrainedlayout_guide.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,13 @@ def docomplicated(suptitle=None):
581581
#
582582
# * There are small differences in how the backends handle rendering fonts,
583583
# so the results will not be pixel-identical.
584+
#
585+
# * An artist using axes coordinates that extend beyond the axes
586+
# boundary will result in unusual layouts when added to an
587+
# axes. This can be avoided by adding the artist directly to the
588+
# :class:`~matplotlib.figure.Figure` using
589+
# :meth:`~matplotlib.figure.Figure.add_artist`. See
590+
# :class:`~matplotlib.patches.ConnectionPatch` for an example.
584591

585592
###########################################################
586593
# Debugging

0 commit comments

Comments
 (0)