Skip to content

Commit d4cb805

Browse files
committed
FIX: Axes.indicate_inset* methods
See #14275 1. Methods now return a tuple as documented, instead of a list. 2. indicate_inset() now does not error when optional inset_ax is not passed, but returns None instead of a tuple.
1 parent 702c583 commit d4cb805

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
`matplotlib.axes.Axes.indicate_inset` returns a 4-tuple as documented
2+
---------------------------------------------------------------------
3+
4+
In <= 3.1.0, `matplotlib.axes.Axes.indicate_inset` and
5+
`matplotlib.axes.Axes.indicate_inset_zoom` were documented as returning
6+
a 4-tuple of `matplotlib.patches.ConnectionPatch`es, where in fact they
7+
returned a 4-length list.
8+
9+
They now correctly return a 4-tuple.
10+
`matplotlib.axes.Axes.indicate_inset` would previously raise an error if
11+
the optional *inset_ax* was not supplied; it now completes successfully,
12+
and returns *None* instead of the tuple of ``ConnectionPatch``es.

lib/matplotlib/axes/_axes.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,12 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
530530
rectangle_patch : `.Patches.Rectangle`
531531
Rectangle artist.
532532
533-
connector_lines : 4-tuple of `.Patches.ConnectionPatch`
534-
One for each of four connector lines. Two are set with visibility
535-
to *False*, but the user can set the visibility to True if the
533+
connector_lines : optional 4-tuple of `.Patches.ConnectionPatch`
534+
Each of four connector lines coming from the given rectangle
535+
on this axes in the order lower left, upper left, lower right,
536+
upper right: *None* if *inset_ax* is *None*.
537+
Two are set with visibility to *False*,
538+
but the user can set the visibility to *True* if the
536539
automatic choice is not deemed correct.
537540
538541
"""
@@ -551,19 +554,24 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
551554
zorder=zorder, label=label, transform=transform, **kwargs)
552555
self.add_patch(rectpatch)
553556

557+
connects = []
558+
554559
if inset_ax is not None:
555560
# want to connect the indicator to the rect....
556-
connects = []
557561
xr = [bounds[0], bounds[0]+bounds[2]]
558562
yr = [bounds[1], bounds[1]+bounds[3]]
559563
for xc in range(2):
560564
for yc in range(2):
561565
xyA = (xc, yc)
562566
xyB = (xr[xc], yr[yc])
563-
connects += [mpatches.ConnectionPatch(xyA, xyB,
567+
connects.append(
568+
mpatches.ConnectionPatch(
569+
xyA, xyB,
564570
'axes fraction', 'data',
565571
axesA=inset_ax, axesB=self, arrowstyle="-",
566-
zorder=zorder, edgecolor=edgecolor, alpha=alpha)]
572+
zorder=zorder, edgecolor=edgecolor, alpha=alpha
573+
)
574+
)
567575
self.add_patch(connects[-1])
568576
# decide which two of the lines to keep visible....
569577
pos = inset_ax.get_position()
@@ -579,7 +587,7 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
579587
connects[2].set_visible(x1 == y0)
580588
connects[3].set_visible(x1 ^ y1)
581589

582-
return rectpatch, connects
590+
return rectpatch, tuple(connects) if connects else None
583591

584592
def indicate_inset_zoom(self, inset_ax, **kwargs):
585593
"""
@@ -601,7 +609,7 @@ def indicate_inset_zoom(self, inset_ax, **kwargs):
601609
chosen so as to not overlap with the indicator box.
602610
603611
**kwargs
604-
Other *kwargs* are passed on to `.Axes.inset_rectangle`
612+
Other *kwargs* are passed on to `.Axes.indicate_inset`
605613
606614
Returns
607615
-------
@@ -610,17 +618,21 @@ def indicate_inset_zoom(self, inset_ax, **kwargs):
610618
Rectangle artist.
611619
612620
connector_lines : 4-tuple of `.Patches.ConnectionPatch`
613-
One for each of four connector lines. Two are set with visibility
614-
to *False*, but the user can set the visibility to True if the
615-
automatic choice is not deemed correct.
621+
Each of four connector lines coming from the rectangle drawn on
622+
this axis, in the order lower left, upper left, lower right,
623+
upper right.
624+
Two are set with visibility to *False*, but the user can
625+
set the visibility to *True* if the automatic choice is not deemed
626+
correct.
616627
617628
"""
618629

619630
xlim = inset_ax.get_xlim()
620631
ylim = inset_ax.get_ylim()
621-
rect = [xlim[0], ylim[0], xlim[1] - xlim[0], ylim[1] - ylim[0]]
632+
rect = (xlim[0], ylim[0], xlim[1] - xlim[0], ylim[1] - ylim[0])
622633
rectpatch, connects = self.indicate_inset(
623-
rect, inset_ax, **kwargs)
634+
rect, inset_ax, **kwargs
635+
)
624636

625637
return rectpatch, connects
626638

0 commit comments

Comments
 (0)