axhline/axvline broken with pint.Quantity · Issue #8910 · matplotlib/matplotlib · GitHub
Skip to content

axhline/axvline broken with pint.Quantity #8910

Description

@dopplershift

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'>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions