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
@@ -516,9 +516,12 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
516
516
rectangle_patch : `.Patches.Rectangle`
517
517
Rectangle artist.
518
518
519
- connector_lines : 4-tuple of `.Patches.ConnectionPatch`
520
- One for each of four connector lines. Two are set with visibility
521
- to *False*, but the user can set the visibility to True if the
519
+ connector_lines : optional 4-tuple of `.Patches.ConnectionPatch`
520
+ Each of four connector lines coming from the given rectangle
521
+ on this axes in the order lower left, upper left, lower right,
522
+ upper right: *None* if *inset_ax* is *None*.
523
+ Two are set with visibility to *False*,
524
+ but the user can set the visibility to *True* if the
522
525
automatic choice is not deemed correct.
523
526
524
527
"""
@@ -537,25 +540,31 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
537
540
zorder = zorder , label = label , transform = transform , ** kwargs )
538
541
self .add_patch (rectpatch )
539
542
543
+ connects = []
544
+
540
545
if inset_ax is not None :
541
546
# want to connect the indicator to the rect....
542
- connects = []
543
547
xr = [bounds [0 ], bounds [0 ]+ bounds [2 ]]
544
548
yr = [bounds [1 ], bounds [1 ]+ bounds [3 ]]
545
549
for xc in range (2 ):
546
550
for yc in range (2 ):
547
551
xyA = (xc , yc )
548
552
xyB = (xr [xc ], yr [yc ])
549
- connects += [mpatches .ConnectionPatch (xyA , xyB ,
553
+ connects .append (
554
+ mpatches .ConnectionPatch (
555
+ xyA , xyB ,
550
556
'axes fraction' , 'data' ,
551
557
axesA = inset_ax , axesB = self , arrowstyle = "-" ,
552
- zorder = zorder , edgecolor = edgecolor , alpha = alpha )]
558
+ zorder = zorder , edgecolor = edgecolor , alpha = alpha
559
+ )
560
+ )
553
561
self .add_patch (connects [- 1 ])
554
562
# decide which two of the lines to keep visible....
555
563
pos = inset_ax .get_position ()
556
564
bboxins = pos .transformed (self .figure .transFigure )
557
565
rectbbox = mtransforms .Bbox .from_bounds (
558
- * bounds ).transformed (transform )
566
+ * bounds
567
+ ).transformed (transform )
559
568
x0 = rectbbox .x0 < bboxins .x0
560
569
x1 = rectbbox .x1 < bboxins .x1
561
570
y0 = rectbbox .y0 < bboxins .y0
@@ -565,7 +574,7 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
565
574
connects [2 ].set_visible (x1 == y0 )
566
575
connects [3 ].set_visible (x1 ^ y1 )
567
576
568
- return rectpatch , connects
577
+ return rectpatch , tuple ( connects ) if connects else None
569
578
570
579
def indicate_inset_zoom (self , inset_ax , ** kwargs ):
571
580
"""
@@ -585,25 +594,29 @@ def indicate_inset_zoom(self, inset_ax, **kwargs):
585
594
chosen so as to not overlap with the indicator box.
586
595
587
596
**kwargs
588
- Other *kwargs* are passed on to `.Axes.inset_rectangle `
597
+ Other *kwargs* are passed on to `.Axes.indicate_inset `
589
598
590
599
Returns
591
600
-------
592
601
rectangle_patch : `.Patches.Rectangle`
593
602
Rectangle artist.
594
603
595
604
connector_lines : 4-tuple of `.Patches.ConnectionPatch`
596
- One for each of four connector lines. Two are set with visibility
597
- to *False*, but the user can set the visibility to True if the
598
- automatic choice is not deemed correct.
605
+ Each of four connector lines coming from the rectangle drawn on
606
+ this axis, in the order lower left, upper left, lower right,
607
+ upper right.
608
+ Two are set with visibility to *False*, but the user can
609
+ set the visibility to *True* if the automatic choice is not deemed
610
+ correct.
599
611
600
612
"""
601
613
602
614
xlim = inset_ax .get_xlim ()
603
615
ylim = inset_ax .get_ylim ()
604
- rect = [ xlim [0 ], ylim [0 ], xlim [1 ] - xlim [0 ], ylim [1 ] - ylim [0 ]]
616
+ rect = ( xlim [0 ], ylim [0 ], xlim [1 ] - xlim [0 ], ylim [1 ] - ylim [0 ])
605
617
rectpatch , connects = self .indicate_inset (
606
- rect , inset_ax , ** kwargs )
618
+ rect , inset_ax , ** kwargs
619
+ )
607
620
608
621
return rectpatch , connects
609
622
0 commit comments