Skip to content

Commit 23f56c8

Browse files
committed
ENH: PEP484 type annotations for inset axes
And minor formatting changes.
1 parent d4cb805 commit 23f56c8

File tree

1 file changed

+45
-14
lines changed

1 file changed

+45
-14
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,22 @@
44
import logging
55
import math
66
from numbers import Number
7+
from typing import Tuple, Optional
78

8-
import numpy as np
9-
from numpy import ma
10-
11-
from matplotlib import _preprocess_data, rcParams
9+
import matplotlib.category as _ # <-registers a category unit converter
1210
import matplotlib.cbook as cbook
1311
import matplotlib.collections as mcoll
1412
import matplotlib.colors as mcolors
1513
import matplotlib.contour as mcontour
16-
import matplotlib.category as _ # <-registers a category unit converter
1714
import matplotlib.dates as _ # <-registers a date unit converter
1815
import matplotlib.docstring as docstring
1916
import matplotlib.image as mimage
2017
import matplotlib.legend as mlegend
2118
import matplotlib.lines as mlines
2219
import matplotlib.markers as mmarkers
2320
import matplotlib.mlab as mlab
24-
import matplotlib.path as mpath
2521
import matplotlib.patches as mpatches
22+
import matplotlib.path as mpath
2623
import matplotlib.quiver as mquiver
2724
import matplotlib.stackplot as mstack
2825
import matplotlib.streamplot as mstream
@@ -31,9 +28,12 @@
3128
import matplotlib.ticker as mticker
3229
import matplotlib.transforms as mtransforms
3330
import matplotlib.tri as mtri
34-
from matplotlib.container import BarContainer, ErrorbarContainer, StemContainer
31+
import numpy as np
32+
from matplotlib import _preprocess_data, rcParams
3533
from matplotlib.axes._base import _AxesBase, _process_plot_format
3634
from matplotlib.axes._secondary_axes import SecondaryAxis
35+
from matplotlib.container import BarContainer, ErrorbarContainer, StemContainer
36+
from numpy import ma
3737

3838
try:
3939
from numpy.lib.histograms import histogram_bin_edges
@@ -408,8 +408,14 @@ def legend(self, *args, **kwargs):
408408
def _remove_legend(self, legend):
409409
self.legend_ = None
410410

411-
def inset_axes(self, bounds, *, transform=None, zorder=5,
412-
**kwargs):
411+
def inset_axes(
412+
self,
413+
bounds: Tuple[float, float, float, float],
414+
*,
415+
transform: Optional[mtransforms.Transform] = None,
416+
zorder: float = 5,
417+
**kwargs
418+
):
413419
"""
414420
Add a child inset axes to this existing axes.
415421
@@ -475,9 +481,25 @@ def inset_axes(self, bounds, *, transform=None, zorder=5,
475481

476482
return inset_ax
477483

478-
def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
479-
facecolor='none', edgecolor='0.5', alpha=0.5,
480-
zorder=4.99, **kwargs):
484+
def indicate_inset(
485+
self,
486+
bounds: Tuple[float, float, float, float],
487+
inset_ax: Optional['Axes'] = None,
488+
*,
489+
transform: Optional[mtransforms.Transform] = None,
490+
facecolor='none',
491+
edgecolor='0.5',
492+
alpha: float = 0.5,
493+
zorder: float = 4.99, **kwargs
494+
) -> Tuple[
495+
mpatches.Rectangle,
496+
Optional[
497+
Tuple[
498+
mpatches.ConnectionPatch, mpatches.ConnectionPatch,
499+
mpatches.ConnectionPatch, mpatches.ConnectionPatch
500+
]
501+
]
502+
]:
481503
"""
482504
Add an inset indicator to the axes. This is a rectangle on the plot
483505
at the position indicated by *bounds* that optionally has lines that
@@ -577,7 +599,8 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
577599
pos = inset_ax.get_position()
578600
bboxins = pos.transformed(self.figure.transFigure)
579601
rectbbox = mtransforms.Bbox.from_bounds(
580-
*bounds).transformed(transform)
602+
*bounds
603+
).transformed(transform)
581604
x0 = rectbbox.x0 < bboxins.x0
582605
x1 = rectbbox.x1 < bboxins.x1
583606
y0 = rectbbox.y0 < bboxins.y0
@@ -589,7 +612,15 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
589612

590613
return rectpatch, tuple(connects) if connects else None
591614

592-
def indicate_inset_zoom(self, inset_ax, **kwargs):
615+
def indicate_inset_zoom(
616+
self, inset_ax: 'Axes', **kwargs
617+
) -> Tuple[
618+
mpatches.Rectangle,
619+
Tuple[
620+
mpatches.ConnectionPatch, mpatches.ConnectionPatch,
621+
mpatches.ConnectionPatch, mpatches.ConnectionPatch
622+
]
623+
]:
593624
"""
594625
Add an inset indicator rectangle to the axes based on the axis
595626
limits for an *inset_ax* and draw connectors between *inset_ax*

0 commit comments

Comments
 (0)