16
16
import matplotlib .contour as mcontour
17
17
import matplotlib .dates # noqa: F401, Register date unit converter as side effect.
18
18
import matplotlib .image as mimage
19
+ import matplotlib .inset as minset
19
20
import matplotlib .legend as mlegend
20
21
import matplotlib .lines as mlines
21
22
import matplotlib .markers as mmarkers
@@ -418,7 +419,7 @@ def inset_axes(self, bounds, *, transform=None, zorder=5, **kwargs):
418
419
return inset_ax
419
420
420
421
@_docstring .dedent_interpd
421
- def indicate_inset (self , bounds , inset_ax = None , * , transform = None ,
422
+ def indicate_inset (self , bounds = None , inset_ax = None , * , transform = None ,
422
423
facecolor = 'none' , edgecolor = '0.5' , alpha = 0.5 ,
423
424
zorder = 4.99 , ** kwargs ):
424
425
"""
@@ -432,11 +433,12 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
432
433
433
434
Parameters
434
435
----------
435
- bounds : [x0, y0, width, height]
436
+ bounds : [x0, y0, width, height], optional
436
437
Lower-left corner of rectangle to be marked, and its width
437
- and height.
438
+ and height. If not set, the bounds will be calculated from the
439
+ data limits of inset_ax, which must be supplied.
438
440
439
- inset_ax : `.Axes`
441
+ inset_ax : `.Axes`, optional
440
442
An optional inset Axes to draw connecting lines to. Two lines are
441
443
drawn connecting the indicator box to the inset Axes on corners
442
444
chosen so as to not overlap with the indicator box.
@@ -468,15 +470,19 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
468
470
469
471
Returns
470
472
-------
471
- rectangle_patch : `.patches.Rectangle`
472
- The indicator frame.
473
+ inset_indicator : `.inset.InsetIndicator` artist containing
473
474
474
- connector_lines : 4-tuple of `.patches.ConnectionPatch`
475
- The four connector lines connecting to (lower_left, upper_left,
476
- lower_right upper_right) corners of *inset_ax*. Two lines are
477
- set with visibility to *False*, but the user can set the
478
- visibility to True if the automatic choice is not deemed correct.
475
+ inset_indicator.rectangle : `.Rectangle`
476
+ The indicator frame.
479
477
478
+ inset_indicator.connectors : 4-tuple of `.patches.ConnectionPatch`
479
+ The four connector lines connecting to (lower_left, upper_left,
480
+ lower_right upper_right) corners of *inset_ax*. Two lines are
481
+ set with visibility to *False*, but the user can set the
482
+ visibility to True if the automatic choice is not deemed correct.
483
+
484
+ .. versionchanged:: 3.10
485
+ Previously the rectangle and connectors tuple were returned.
480
486
"""
481
487
# to make the Axes connectors work, we need to apply the aspect to
482
488
# the parent Axes.
@@ -486,51 +492,13 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
486
492
transform = self .transData
487
493
kwargs .setdefault ('label' , '_indicate_inset' )
488
494
489
- x , y , width , height = bounds
490
- rectangle_patch = mpatches .Rectangle (
491
- (x , y ), width , height ,
495
+ indicator_patch = minset .InsetIndicator (
496
+ bounds , inset_ax = inset_ax ,
492
497
facecolor = facecolor , edgecolor = edgecolor , alpha = alpha ,
493
498
zorder = zorder , transform = transform , ** kwargs )
494
- self .add_patch (rectangle_patch )
495
-
496
- connects = []
497
-
498
- if inset_ax is not None :
499
- # connect the inset_axes to the rectangle
500
- for xy_inset_ax in [(0 , 0 ), (0 , 1 ), (1 , 0 ), (1 , 1 )]:
501
- # inset_ax positions are in axes coordinates
502
- # The 0, 1 values define the four edges if the inset_ax
503
- # lower_left, upper_left, lower_right upper_right.
504
- ex , ey = xy_inset_ax
505
- if self .xaxis .get_inverted ():
506
- ex = 1 - ex
507
- if self .yaxis .get_inverted ():
508
- ey = 1 - ey
509
- xy_data = x + ex * width , y + ey * height
510
- p = mpatches .ConnectionPatch (
511
- xyA = xy_inset_ax , coordsA = inset_ax .transAxes ,
512
- xyB = xy_data , coordsB = self .transData ,
513
- arrowstyle = "-" , zorder = zorder ,
514
- edgecolor = edgecolor , alpha = alpha )
515
- connects .append (p )
516
- self .add_patch (p )
517
-
518
- # decide which two of the lines to keep visible....
519
- pos = inset_ax .get_position ()
520
- bboxins = pos .transformed (self .figure .transSubfigure )
521
- rectbbox = mtransforms .Bbox .from_bounds (
522
- * bounds
523
- ).transformed (transform )
524
- x0 = rectbbox .x0 < bboxins .x0
525
- x1 = rectbbox .x1 < bboxins .x1
526
- y0 = rectbbox .y0 < bboxins .y0
527
- y1 = rectbbox .y1 < bboxins .y1
528
- connects [0 ].set_visible (x0 ^ y0 )
529
- connects [1 ].set_visible (x0 == y1 )
530
- connects [2 ].set_visible (x1 == y0 )
531
- connects [3 ].set_visible (x1 ^ y1 )
532
-
533
- return rectangle_patch , tuple (connects ) if connects else None
499
+ self .add_artist (indicator_patch )
500
+
501
+ return indicator_patch
534
502
535
503
def indicate_inset_zoom (self , inset_ax , ** kwargs ):
536
504
"""
@@ -554,22 +522,22 @@ def indicate_inset_zoom(self, inset_ax, **kwargs):
554
522
555
523
Returns
556
524
-------
557
- rectangle_patch : `.patches.Rectangle`
558
- Rectangle artist.
559
-
560
- connector_lines : 4-tuple of `.patches.ConnectionPatch`
561
- Each of four connector lines coming from the rectangle drawn on
562
- this axis, in the order lower left, upper left, lower right,
563
- upper right.
564
- Two are set with visibility to *False*, but the user can
565
- set the visibility to *True* if the automatic choice is not deemed
566
- correct.
525
+ inset_indicator : `.inset.InsetIndicator` artist containing
526
+
527
+ inset_indicator.rectangle : `.Rectangle`
528
+ The indicator frame.
529
+
530
+ inset_indicator.connectors : 4-tuple of `.patches.ConnectionPatch`
531
+ The four connector lines connecting to (lower_left, upper_left,
532
+ lower_right upper_right) corners of *inset_ax*. Two lines are
533
+ set with visibility to *False*, but the user can set the
534
+ visibility to True if the automatic choice is not deemed correct.
535
+
536
+ .. versionchanged:: 3.10
537
+ Previously the rectangle and connectors tuple were returned.
567
538
"""
568
539
569
- xlim = inset_ax .get_xlim ()
570
- ylim = inset_ax .get_ylim ()
571
- rect = (xlim [0 ], ylim [0 ], xlim [1 ] - xlim [0 ], ylim [1 ] - ylim [0 ])
572
- return self .indicate_inset (rect , inset_ax , ** kwargs )
540
+ return self .indicate_inset (None , inset_ax , ** kwargs )
573
541
574
542
@_docstring .dedent_interpd
575
543
def secondary_xaxis (self , location , functions = None , * , transform = None , ** kwargs ):
0 commit comments