8000 Add _can_unconvert_units property · matplotlib/matplotlib@01ecaca · GitHub
[go: up one dir, main page]

Skip to content

Commit 01ecaca

Browse files
committed
Add _can_unconvert_units property
1 parent fa85f95 commit 01ecaca

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3176,7 +3176,7 @@ def _convert_back_lim(self, lim, axis):
31763176
"""
31773177
Helper method to convert axis limits back to unitized data.
31783178
"""
3179-
if axis.converter is not None:
3179+
if axis._can_unconvert_units:
31803180
lim = [axis.converter.un_convert(l, axis.units, axis) for
31813181
l in lim]
31823182
return tuple(lim)

lib/matplotlib/axis.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1581,8 +1581,15 @@ def convert_units(self, x):
15811581
f'units: {x!r}') from e
15821582
return ret
15831583

1584+
@property
1585+
def _can_unconvert_units(self):
1586+
if self.converter is not None:
1587+
if hasattr(self.converter, 'un_convert'):
1588+
return True
1589+
return False
1590+
15841591
def unconvert_units(self, x):
1585-
if self.converter is None:
1592+
if not self._can_unconvert_units:
15861593
return x
15871594
return self.converter.un_convert(x, self.units, self)
15881595

0 commit comments

Comments
 (0)
0