8
8
import numpy as np
9
9
from numpy import ma
10
10
11
- from matplotlib import _preprocess_data , rcParams
11
+ import matplotlib . category as _ # <-registers a category unit converter
12
12
import matplotlib .cbook as cbook
13
13
import matplotlib .collections as mcoll
14
14
import matplotlib .colors as mcolors
15
15
import matplotlib .contour as mcontour
16
- import matplotlib .category as _ # <-registers a category unit converter
17
16
import matplotlib .dates as _ # <-registers a date unit converter
18
17
import matplotlib .docstring as docstring
19
18
import matplotlib .image as mimage
20
19
import matplotlib .legend as mlegend
21
20
import matplotlib .lines as mlines
22
21
import matplotlib .markers as mmarkers
23
22
import matplotlib .mlab as mlab
24
- import matplotlib .path as mpath
25
23
import matplotlib .patches as mpatches
24
+ import matplotlib .path as mpath
26
25
import matplotlib .quiver as mquiver
27
26
import matplotlib .stackplot as mstack
28
27
import matplotlib .streamplot as mstream
31
30
import matplotlib .ticker as mticker
32
31
import matplotlib .transforms as mtransforms
33
32
import matplotlib .tri as mtri
34
- from matplotlib . container import BarContainer , ErrorbarContainer , StemContainer
33
+ from matplotlib import _preprocess_data , rcParams
35
34
from matplotlib .axes ._base import _AxesBase , _process_plot_format
36
35
from matplotlib .axes ._secondary_axes import SecondaryAxis
36
+ from matplotlib .container import BarContainer , ErrorbarContainer , StemContainer
37
37
38
38
try :
39
39
from numpy .lib .histograms import histogram_bin_edges
@@ -514,9 +514,12 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
514
514
rectangle_patch : `.Patches.Rectangle`
515
515
Rectangle artist.
516
516
517
- connector_lines : 4-tuple of `.Patches.ConnectionPatch`
518
- One for each of four connector lines. Two are set with visibility
519
- to *False*, but the user can set the visibility to True if the
517
+ connector_lines : optional 4-tuple of `.Patches.ConnectionPatch`
518
+ Each of four connector lines coming from the given rectangle
519
+ on this axes in the order lower left, upper left, lower right,
520
+ upper right: *None* if *inset_ax* is *None*.
521
+ Two are set with visibility to *False*,
522
+ but the user can set the visibility to *True* if the
520
523
automatic choice is not deemed correct.
521
524
522
525
"""
@@ -535,25 +538,31 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
535
538
zorder = zorder , label = label , transform = transform , ** kwargs )
536
539
self .add_patch (rectpatch )
537
540
541
+ connects = []
542
+
538
543
if inset_ax is not None :
539
544
# want to connect the indicator to the rect....
540
- connects = []
541
545
xr = [bounds [0 ], bounds [0 ]+ bounds [2 ]]
542
546
yr = [bounds [1 ], bounds [1 ]+ bounds [3 ]]
543
547
for xc in range (2 ):
544
548
for yc in range (2 ):
545
549
xyA = (xc , yc )
546
550
xyB = (xr [xc ], yr [yc ])
547
- connects += [mpatches .ConnectionPatch (xyA , xyB ,
551
+ connects .append (
552
+ mpatches .ConnectionPatch (
553
+ xyA , xyB ,
548
554
'axes fraction' , 'data' ,
549
555
axesA = inset_ax , axesB = self , arrowstyle = "-" ,
550
- zorder = zorder , edgecolor = edgecolor , alpha = alpha )]
556
+ zorder = zorder , edgecolor = edgecolor , alpha = alpha
557
+ )
558
+ )
551
559
self .add_patch (connects [- 1 ])
552
560
# decide which two of the lines to keep visible....
553
561
pos = inset_ax .get_position ()
554
562
bboxins = pos .transformed (self .figure .transFigure )
555
563
rectbbox = mtransforms .Bbox .from_bounds (
556
- * bounds ).transformed (transform )
564
+ * bounds
565
+ ).transformed (transform )
557
566
x0 = rectbbox .x0 < bboxins .x0
558
567
x1 = rectbbox .x1 < bboxins .x1
559
568
y0 = rectbbox .y0 < bboxins .y0
@@ -563,7 +572,7 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
563
572
connects [2 ].set_visible (x1 == y0 )
564
573
connects [3 ].set_visible (x1 ^ y1 )
565
574
566
- return rectpatch , connects
575
+ return rectpatch , tuple ( connects ) if connects else None
567
576
568
577
def indicate_inset_zoom (self , inset_ax , ** kwargs ):
569
578
"""
@@ -583,25 +592,29 @@ def indicate_inset_zoom(self, inset_ax, **kwargs):
583
592
chosen so as to not overlap with the indicator box.
584
593
585
594
**kwargs
586
- Other *kwargs* are passed on to `.Axes.inset_rectangle `
595
+ Other *kwargs* are passed on to `.Axes.indicate_inset `
587
596
588
597
Returns
589
598
-------
590
599
rectangle_patch : `.Patches.Rectangle`
591
600
Rectangle artist.
592
601
593
602
connector_lines : 4-tuple of `.Patches.ConnectionPatch`
594
- One for each of four connector lines. Two are set with visibility
595
- to *False*, but the user can set the visibility to True if the
596
- automatic choice is not deemed correct.
603
+ Each of four connector lines coming from the rectangle drawn on
604
+ this axis, in the order lower left, upper left, lower right,
605
+ upper right.
606
+ Two are set with visibility to *False*, but the user can
607
+ set the visibility to *True* if the automatic choice is not deemed
608
+ correct.
597
609
598
610
"""
599
611
600
612
xlim = inset_ax .get_xlim ()
601
613
ylim = inset_ax .get_ylim ()
602
- rect = [ xlim [0 ], ylim [0 ], xlim [1 ] - xlim [0 ], ylim [1 ] - ylim [0 ]]
614
+ rect = ( xlim [0 ], ylim [0 ], xlim [1 ] - xlim [0 ], ylim [1 ] - ylim [0 ])
603
615
rectpatch , connects = self .indicate_inset (
604
- rect , inset_ax , ** kwargs )
616
+ rect , inset_ax , ** kwargs
617
+ )
605
618
606
619
return rectpatch , connects
607
620
0 commit comments