Closed
Description
With matplotlib 2.0.2, you can't use pint.Quantity with axhline
or axvline
:
%matplotlib inline
import matplotlib.pyplot as plt
import pint
units = pint.UnitRegistry()
fig, axes = plt.subplots(1, 1)
axes.axhline(0 * units.meter)
yields:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-3-b77d6298b805> in <module>()
6 units = pint.UnitRegistry()
7 fig, axes = plt.subplots(1, 1)
----> 8 axes.axhline(0 * units.meter)
~/miniconda3/envs/py36/lib/python3.6/site-packages/matplotlib/axes/_axes.py in axhline(self, y, xmin, xmax, **kwargs)
720 self._process_unit_info(ydata=y, kwargs=kwargs)
721 yy = self.convert_yunits(y)
--> 722 scaley = (yy < ymin) or (yy > ymax)
723
724 trans = self.get_yaxis_transform(which='grid')
~/miniconda3/envs/py36/lib/python3.6/site-packages/pint/quantity.py in <lambda>(self, other)
1075 other.to_root_units().magnitude)
1076
-> 1077 __lt__ = lambda self, other: self.compare(other, op=operator.lt)
1078 __le__ = lambda self, other: self.compare(other, op=operator.le)
1079 __ge__ = lambda self, other: self.compare(other, op=operator.ge)
~/miniconda3/envs/py36/lib/python3.6/site-packages/pint/quantity.py in compare(self, other, op)
1065 return op(self._convert_magnitude_not_inplace(UnitsContainer()), other)
1066 else:
-> 1067 raise ValueError('Cannot compare Quantity and {0}'.format(type(other)))
1068
1069 if self._units == other._units:
ValueError: Cannot compare Quantity and <class 'numpy.float64'>