Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 296b5ff

Browse files
authored
Merge pull request #10206 from dstansby/dont-convert-numbers
Don't convert numbers plotted on an axis with units
2 parents 6943d24 + 4f25759 commit 296b5ff

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

lib/matplotlib/axis.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,10 @@ def have_units(self):
14981498
return self.converter is not None or self.units is not None
14991499

15001500
def convert_units(self, x):
1501+
# If x is already a number, doesn't need converting
1502+
if munits.ConversionInterface.is_numlike(x):
1503+
return x
1504+
15011505
if self.converter is None:
15021506
self.converter = munits.registry.get_converter(x)
15031507

lib/matplotlib/dates.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,8 +1804,6 @@ def convert(value, unit, axis):
18041804
18051805
The *unit* and *axis* arguments are not used.
18061806
"""
1807-
if units.ConversionInterface.is_numlike(value):
1808-
return value
18091807
return date2num(value)
18101808

18111809
@staticmethod

lib/matplotlib/tests/test_units.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ def __getattr__(self, attr):
3131
return getattr(self.magnitude, attr)
3232

3333
def __getitem__(self, item):
34-
return Quantity(self.magnitude[item], self.units)
34+
if iterable(self.magnitude):
35+
return Quantity(self.magnitude[item], self.units)
36+
else:
37+
return Quantity(self.magnitude, self.units)
3538

3639
def __array__(self):
3740
return np.asarray(self.magnitude)

0 commit comments

Comments
 (0)