Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ksunden committed Oct 23, 2024
1 parent 12f4078 commit 4bb8c8d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
27 changes: 22 additions & 5 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ def __init__(self, axes, *, pickradius=15, clear=True):
self.clear()
else:
self.converter = None
self._explicit_converter = False
self._converter_is_explicit = False
self.units = None

self._autoscale_on = True
Expand Down Expand Up @@ -888,7 +888,7 @@ def clear(self):
self.reset_ticks()

self.converter = None
self._explicit_converter = False
self._converter_is_explicit = False
self.units = None
self.stale = True

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

def get_converter(self):
"""
Get the unit converter for axis.
Returns
-------
`~matplotlib.units.ConversionInterface` or None
"""
return self.converter

def set_converter(self, converter):
"""
Set the unit converter for axis.
Parameters
----------
converter : `~matplotlib.dates.ConversionInterface`
"""
self._set_converter(converter)
self._explicit_converter = True
self._converter_is_explicit = True

def _set_converter(self, converter):
if self.converter == converter:
return
if self._explicit_converter:
if self._converter_is_explicit:
raise RuntimeError("Axis already has an explicit converter set")
elif self.converter is not None:
_api.warn_external(
Expand Down
3 changes: 3 additions & 0 deletions lib/matplotlib/axis.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ from matplotlib.text import Text
from matplotlib.ticker import Locator, Formatter
from matplotlib.transforms import Transform, Bbox
from matplotlib.typing import ColorType
from matplotlib.units import ConversionInterface


GRIDLINE_INTERPOLATION_STEPS: int
Expand Down Expand Up @@ -207,6 +208,8 @@ class Axis(martist.Artist):
def update_units(self, data): ...
def have_units(self) -> bool: ...
def convert_units(self, x): ...
def get_converter(self) -> ConversionInterface | None: ...
def set_converter(self, converter: ConversionInterface) -> None: ...
def set_units(self, u) -> None: ...
def get_units(self): ...
def set_label_text(
Expand Down

0 comments on commit 4bb8c8d

Please sign in to comment.