File tree Expand file tree Collapse file tree 2 files changed +9
-8
lines changed Expand file tree Collapse file tree 2 files changed +9
-8
lines changed Original file line number Diff line number Diff line change 31
31
xyA = xy , coordsA = ax2 .transData ,
32
32
xyB = xy , coordsB = ax1 .transData ,
33
33
arrowstyle = "->" , shrinkB = 5 )
34
- ax2 .add_artist (con )
34
+ fig .add_artist (con )
35
35
36
36
# Draw a line between the different points, defined in different coordinate
37
37
# systems.
Original file line number Diff line number Diff line change 499
499
Using ConnectionPatch
500
500
~~~~~~~~~~~~~~~~~~~~~
501
501
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. ::
505
505
506
506
from matplotlib.patches import ConnectionPatch
507
507
xy = (0.2, 0.2)
508
508
con = ConnectionPatch(xyA=xy, coordsA=ax1.transData,
509
509
xyB=xy, coordsB=ax2.transData)
510
- ax2 .add_artist(con)
510
+ fig .add_artist(con)
511
511
512
512
The above code connects point *xy* in the data coordinates of ``ax1`` to
513
513
point *xy* in the data coordinates of ``ax2``. Here is a simple example.
519
519
520
520
Connect Simple01
521
521
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.
525
526
526
527
Advanced Topics
527
528
---------------
You can’t perform that action at this time.
0 commit comments