1616import matplotlib .contour as mcontour
1717import matplotlib .dates # noqa: F401, Register date unit converter as side effect.
1818import matplotlib .image as mimage
19+ import matplotlib .inset as minset
1920import matplotlib .legend as mlegend
2021import matplotlib .lines as mlines
2122import matplotlib .markers as mmarkers
@@ -419,9 +420,9 @@ def inset_axes(self, bounds, *, transform=None, zorder=5, **kwargs):
419420 return inset_ax
420421
421422 @_docstring .interpd
422- def indicate_inset (self , bounds , inset_ax = None , * , transform = None ,
423+ def indicate_inset (self , bounds = None , inset_ax = None , * , transform = None ,
423424 facecolor = 'none' , edgecolor = '0.5' , alpha = 0.5 ,
424- zorder = 4.99 , ** kwargs ):
425+ zorder = None , ** kwargs ):
425426 """
426427 Add an inset indicator to the Axes. This is a rectangle on the plot
427428 at the position indicated by *bounds* that optionally has lines that
@@ -433,18 +434,19 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
433434
434435 Parameters
435436 ----------
436- bounds : [x0, y0, width, height]
437+ bounds : [x0, y0, width, height], optional
437438 Lower-left corner of rectangle to be marked, and its width
438- and height.
439+ and height. If not set, the bounds will be calculated from the
440+ data limits of *inset_ax*, which must be supplied.
439441
440- inset_ax : `.Axes`
442+ inset_ax : `.Axes`, optional
441443 An optional inset Axes to draw connecting lines to. Two lines are
442444 drawn connecting the indicator box to the inset Axes on corners
443445 chosen so as to not overlap with the indicator box.
444446
445447 transform : `.Transform`
446448 Transform for the rectangle coordinates. Defaults to
447- `ax.transAxes`, i.e. the units of *rect* are in Axes-relative
449+ `` ax.transAxes` `, i.e. the units of *rect* are in Axes-relative
448450 coordinates.
449451
450452 facecolor : :mpltype:`color`, default: 'none'
@@ -469,15 +471,20 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
469471
470472 Returns
471473 -------
472- rectangle_patch : `.patches.Rectangle `
473- The indicator frame.
474+ inset_indicator : `.inset.InsetIndicator `
475+ An artist which contains
474476
475- connector_lines : 4-tuple of `.patches.ConnectionPatch`
476- The four connector lines connecting to (lower_left, upper_left,
477- lower_right upper_right) corners of *inset_ax*. Two lines are
478- set with visibility to *False*, but the user can set the
479- visibility to True if the automatic choice is not deemed correct.
477+ inset_indicator.rectangle : `.Rectangle`
478+ The indicator frame.
480479
480+ inset_indicator.connectors : 4-tuple of `.patches.ConnectionPatch`
481+ The four connector lines connecting to (lower_left, upper_left,
482+ lower_right upper_right) corners of *inset_ax*. Two lines are
483+ set with visibility to *False*, but the user can set the
484+ visibility to True if the automatic choice is not deemed correct.
485+
486+ .. versionchanged:: 3.10
487+ Previously the rectangle and connectors tuple were returned.
481488 """
482489 # to make the Axes connectors work, we need to apply the aspect to
483490 # the parent Axes.
@@ -487,51 +494,13 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
487494 transform = self .transData
488495 kwargs .setdefault ('label' , '_indicate_inset' )
489496
490- x , y , width , height = bounds
491- rectangle_patch = mpatches .Rectangle (
492- (x , y ), width , height ,
497+ indicator_patch = minset .InsetIndicator (
498+ bounds , inset_ax = inset_ax ,
493499 facecolor = facecolor , edgecolor = edgecolor , alpha = alpha ,
494500 zorder = zorder , transform = transform , ** kwargs )
495- self .add_patch (rectangle_patch )
496-
497- connects = []
498-
499- if inset_ax is not None :
500- # connect the inset_axes to the rectangle
501- for xy_inset_ax in [(0 , 0 ), (0 , 1 ), (1 , 0 ), (1 , 1 )]:
502- # inset_ax positions are in axes coordinates
503- # The 0, 1 values define the four edges if the inset_ax
504- # lower_left, upper_left, lower_right upper_right.
505- ex , ey = xy_inset_ax
506- if self .xaxis .get_inverted ():
507- ex = 1 - ex
508- if self .yaxis .get_inverted ():
509- ey = 1 - ey
510- xy_data = x + ex * width , y + ey * height
511- p = mpatches .ConnectionPatch (
512- xyA = xy_inset_ax , coordsA = inset_ax .transAxes ,
513- xyB = xy_data , coordsB = self .transData ,
514- arrowstyle = "-" , zorder = zorder ,
515- edgecolor = edgecolor , alpha = alpha )
516- connects .append (p )
517- self .add_patch (p )
518-
519- # decide which two of the lines to keep visible....
520- pos = inset_ax .get_position ()
521- bboxins = pos .transformed (self .get_figure (root = False ).transSubfigure )
522- rectbbox = mtransforms .Bbox .from_bounds (
523- * bounds
524- ).transformed (transform )
525- x0 = rectbbox .x0 < bboxins .x0
526- x1 = rectbbox .x1 < bboxins .x1
527- y0 = rectbbox .y0 < bboxins .y0
528- y1 = rectbbox .y1 < bboxins .y1
529- connects [0 ].set_visible (x0 ^ y0 )
530- connects [1 ].set_visible (x0 == y1 )
531- connects [2 ].set_visible (x1 == y0 )
532- connects [3 ].set_visible (x1 ^ y1 )
533-
534- return rectangle_patch , tuple (connects ) if connects else None
501+ self .add_artist (indicator_patch )
502+
503+ return indicator_patch
535504
536505 def indicate_inset_zoom (self , inset_ax , ** kwargs ):
537506 """
@@ -555,22 +524,23 @@ def indicate_inset_zoom(self, inset_ax, **kwargs):
555524
556525 Returns
557526 -------
558- rectangle_patch : `.patches.Rectangle`
559- Rectangle artist.
560-
561- connector_lines : 4-tuple of `.patches.ConnectionPatch`
562- Each of four connector lines coming from the rectangle drawn on
563- this axis, in the order lower left, upper left, lower right,
564- upper right.
565- Two are set with visibility to *False*, but the user can
566- set the visibility to *True* if the automatic choice is not deemed
567- correct.
527+ inset_indicator : `.inset.InsetIndicator`
528+ An artist which contains
529+
530+ inset_indicator.rectangle : `.Rectangle`
531+ The indicator frame.
532+
533+ inset_indicator.connectors : 4-tuple of `.patches.ConnectionPatch`
534+ The four connector lines connecting to (lower_left, upper_left,
535+ lower_right upper_right) corners of *inset_ax*. Two lines are
536+ set with visibility to *False*, but the user can set the
537+ visibility to True if the automatic choice is not deemed correct.
538+
539+ .. versionchanged:: 3.10
540+ Previously the rectangle and connectors tuple were returned.
568541 """
569542
570- xlim = inset_ax .get_xlim ()
571- ylim = inset_ax .get_ylim ()
572- rect = (xlim [0 ], ylim [0 ], xlim [1 ] - xlim [0 ], ylim [1 ] - ylim [0 ])
573- return self .indicate_inset (rect , inset_ax , ** kwargs )
543+ return self .indicate_inset (None , inset_ax , ** kwargs )
574544
575545 @_docstring .interpd
576546 def secondary_xaxis (self , location , functions = None , * , transform = None , ** kwargs ):
0 commit comments