8000 Fix unit info setting axis label · ksunden/matplotlib@31dee3a · GitHub
[go: up one dir, main page]

Skip to content

Commit 31dee3a

Browse files
committed
Fix unit info setting axis label
1 parent d9169cb commit 31dee3a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2580,7 +2580,9 @@ def _process_unit_info(self, datasets=None, kwargs=None, *, convert=True):
25802580
except KeyError:
25812581
raise ValueError(f"Invalid axis name: {axis_name!r}") from None
25822582
# Update from data if axis is already set but no unit is set yet.
2583-
if axis is not None and data is not None and not axis.have_units():
2583+
if (axis is not None and
2584+
data is not None and not
2585+
axis.have_units_and_converter()):
25842586
axis.update_units(data)
25852587
for axis_name, axis in axis_map.items():
25862588
# Return if no axis is set.

lib/matplotlib/axis.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,8 +1652,17 @@ def _update_axisinfo(self):
16521652
self.set_default_intervals()
16531653

16541654
def have_units 87BF (self):
1655+
"""
1656+
Return `True` if units or a converter have been set.
1657+
"""
16551658
return self.converter is not None or self.units is not None
16561659

1660+
def have_units_and_converter(self):
1661+
"""
1662+
Return `True` if units and a converter have been set.
1663+
"""
1664+
return self.converter is not None and self.units is not None
1665+
16571666
def convert_units(self, x):
16581667
# If x is natively supported by Matplotlib, doesn't need converting
16591668
if munits._is_natively_supported(x):

0 commit comments

Comments
 (0)
0