Skip to content

Commit babef61

Browse files
committed
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."
1 parent 25b80c3 commit babef61

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

examples/userdemo/connect_simple01.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
xyA=xy, coordsA=ax2.transData,
3232
xyB=xy, coordsB=ax1.transData,
3333
arrowstyle="->", shrinkB=5)
34-
ax2.add_artist(con)
34+
fig.add_artist(con)
3535

3636
# Draw a line between the different points, defined in different coordinate
3737
# systems.

tutorials/text/annotations.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -499,15 +499,15 @@
499499
Using ConnectionPatch
500500
~~~~~~~~~~~~~~~~~~~~~
501501
502-
The ConnectionPatch is like an annotation without text. While the annotate
503-
function is recommended in most situations, the ConnectionPatch is useful when
504-
you want to connect points in different axes. ::
502+
ConnectionPatch is like an annotation without text. While `~.Axes.annotate`
503+
is sufficient in most situations, ConnectionPatch is useful when you want to
504+
connect points in different axes. ::
505505
506506
from matplotlib.patches import ConnectionPatch
507507
xy = (0.2, 0.2)
508508
con = ConnectionPatch(xyA=xy, coordsA=ax1.transData,
509509
xyB=xy, coordsB=ax2.transData)
510-
ax2.add_artist(con)
510+
fig.add_artist(con)
511511
512512
The above code connects point *xy* in the data coordinates of ``ax1`` to
513513
point *xy* in the data coordinates of ``ax2``. Here is a simple example.
@@ -519,9 +519,10 @@
519519
520520
Connect Simple01
521521
522-
While the ConnectionPatch instance can be added to any axes, you may want to
523-
add it to the axes that is drawn last, to prevent it from being covered by
524-
other axes.
522+
Here, we added the ConnectionPatch to the *figure* (with `~.Figure.add_artist`)
523+
rather than to either axes: this ensures that it is drawn on top of both axes,
524+
and is also necessary if using :doc:`constrained_layout
525+
</tutorials/intermediate/constrainedlayout_guide>` for positioning the axes.
525526
526527
Advanced Topics
527528
---------------

0 commit comments

Comments
 (0)