Skip to content

Commit 7acb640

Browse files
committed
Fix unit info setting axis label
1 parent c9da8d0 commit 7acb640

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
@@ -2549,7 +2549,9 @@ def _process_unit_info(self, datasets=None, kwargs=None, *, convert=True):
25492549
except KeyError:
25502550
raise ValueError(f"Invalid axis name: {axis_name!r}") from None
25512551
# Update from data if axis is already set but no unit is set yet.
2552-
if axis is not None and data is not None and not axis.have_units():
2552+
if (axis is not None and
2553+
data is not None and not
2554+
axis.have_units_and_converter()):
25532555
axis.update_units(data)
25542556
for axis_name, axis in axis_map.items():
25552557
# Return if no axis is set.

lib/matplotlib/axis.py

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

16121612
def have_units(self):
1613+
"""
1614+
Return `True` if units or a converter have been set.
1615+
"""
16131616
return self.converter is not None or self.units is not None
16141617

1618+
def have_units_and_converter(self):
1619+
"""
1620+
Return `True` if units and a converter have been set.
1621+
"""
1622+
return self.converter is not None and self.units is not None
1623+
16151624
def convert_units(self, x):
16161625
# If x is natively supported by Matplotlib, doesn't need converting
16171626
if munits._is_natively_supported(x):

0 commit comments

Comments
 (0)