Skip to content

Commit 4bb8c8d

Browse files
committed
Review comments
1 parent 12f4078 commit 4bb8c8d

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

lib/matplotlib/axis.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ def __init__(self, axes, *, pickradius=15, clear=True):
657657
self.clear()
658658
else:
659659
self.converter = None
660-
self._explicit_converter = False
660+
self._converter_is_explicit = False
661661
self.units = None
662662

663663
self._autoscale_on = True
@@ -888,7 +888,7 @@ def clear(self):
888888
self.reset_ticks()
889889

890890
self.converter = None
891-
self._explicit_converter = False
891+
self._converter_is_explicit = False
892892
self.units = None
893893
self.stale = True
894894

@@ -1743,7 +1743,7 @@ def update_units(self, data):
17431743
``axis.converter`` instance if necessary. Return *True*
17441744
if *data* is registered for unit conversion.
17451745
"""
1746-
if not self._explicit_converter:
1746+
if not self._converter_is_explicit:
17471747
converter = munits.registry.get_converter(data)
17481748
else:
17491749
converter = self.converter
@@ -1816,14 +1816,31 @@ def convert_units(self, x):
18161816
f'units: {x!r}') from e
18171817
return ret
18181818

1819+
def get_converter(self):
1820+
"""
1821+
Get the unit converter for axis.
1822+
1823+
Returns
1824+
-------
1825+
`~matplotlib.units.ConversionInterface` or None
1826+
"""
1827+
return self.converter
1828+
18191829
def set_converter(self, converter):
1830+
"""
1831+
Set the unit converter for axis.
1832+
1833+
Parameters
1834+
----------
1835+
converter : `~matplotlib.dates.ConversionInterface`
1836+
"""
18201837
self._set_converter(converter)
1821-
self._explicit_converter = True
1838+
self._converter_is_explicit = True
18221839

18231840
def _set_converter(self, converter):
18241841
if self.converter == converter:
18251842
return
1826-
if self._explicit_converter:
1843+
if self._converter_is_explicit:
18271844
raise RuntimeError("Axis already has an explicit converter set")
18281845
elif self.converter is not None:
18291846
_api.warn_external(

lib/matplotlib/axis.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ from matplotlib.text import Text
1515
from matplotlib.ticker import Locator, Formatter
1616
from matplotlib.transforms import Transform, Bbox
1717
from matplotlib.typing import ColorType
18+
from matplotlib.units import ConversionInterface
1819

1920

2021
GRIDLINE_INTERPOLATION_STEPS: int
@@ -207,6 +208,8 @@ class Axis(martist.Artist):
207208
def update_units(self, data): ...
208209
def have_units(self) -> bool: ...
209210
def convert_units(self, x): ...
211+
def get_converter(self) -> ConversionInterface | None: ...
212+
def set_converter(self, converter: ConversionInterface) -> None: ...
210213
def set_units(self, u) -> None: ...
211214
def get_units(self): ...
212215
def set_label_text(

0 commit comments

Comments
 (0)