From babef61b56a2193109af4761968636dc60d53b3a Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 4 Mar 2020 10:34:05 +0100 Subject: [PATCH] In docs, add multi-axes connectionpatches to Figure, not Axes. Per the new tutorial text: "this ensures that it is drawn on top of both axes, and is also necessary if using constrained_layout for positioning the axes." --- examples/userdemo/connect_simple01.py | 2 +- tutorials/text/annotations.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/userdemo/connect_simple01.py b/examples/userdemo/connect_simple01.py index 5896004a52f2..f8769e39401f 100644 --- a/examples/userdemo/connect_simple01.py +++ b/examples/userdemo/connect_simple01.py @@ -31,7 +31,7 @@ xyA=xy, coordsA=ax2.transData, xyB=xy, coordsB=ax1.transData, arrowstyle="->", shrinkB=5) -ax2.add_artist(con) +fig.add_artist(con) # Draw a line between the different points, defined in different coordinate # systems. diff --git a/tutorials/text/annotations.py b/tutorials/text/annotations.py index e1e2754be49c..aeada6ea1c9c 100644 --- a/tutorials/text/annotations.py +++ b/tutorials/text/annotations.py @@ -499,15 +499,15 @@ Using ConnectionPatch ~~~~~~~~~~~~~~~~~~~~~ -The ConnectionPatch is like an annotation without text. While the annotate -function is recommended in most situations, the ConnectionPatch is useful when -you want to connect points in different axes. :: +ConnectionPatch is like an annotation without text. While `~.Axes.annotate` +is sufficient in most situations, ConnectionPatch is useful when you want to +connect points in different axes. :: from matplotlib.patches import ConnectionPatch xy = (0.2, 0.2) con = ConnectionPatch(xyA=xy, coordsA=ax1.transData, xyB=xy, coordsB=ax2.transData) - ax2.add_artist(con) + fig.add_artist(con) The above code connects point *xy* in the data coordinates of ``ax1`` to point *xy* in the data coordinates of ``ax2``. Here is a simple example. @@ -519,9 +519,10 @@ Connect Simple01 -While the ConnectionPatch instance can be added to any axes, you may want to -add it to the axes that is drawn last, to prevent it from being covered by -other axes. +Here, we added the ConnectionPatch to the *figure* (with `~.Figure.add_artist`) +rather than to either axes: this ensures that it is drawn on top of both axes, +and is also necessary if using :doc:`constrained_layout +` for positioning the axes. Advanced Topics ---------------