File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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.
Original file line number Diff line number Diff line change 499499Using 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
512512The above code connects point *xy* in the data coordinates of ``ax1`` to
513513point *xy* in the data coordinates of ``ax2``. Here is a simple example.
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
526527Advanced Topics
527528---------------
You can’t perform that action at this time.
0 commit comments