Skip to content

Quantities notebook breaks with matplotlib v3.1 #359

@eblur

Description

@eblur

CircleCI tests fail on Quantities tutorial now.

plt.figure()
plt.hist(v, bins='auto', histtype="step")
plt.xlabel("Velocity (km/s)")
plt.ylabel("N")
------------------


UnitConversionErrorTraceback (most recent call last)
~/project/venv/lib/python3.6/site-packages/astropy/units/quantity.py in to_value(self, unit, equivalencies)
    708             try:
--> 709                 scale = self.unit._to(unit)
    710             except Exception:

~/project/venv/lib/python3.6/site-packages/astropy/units/core.py in _to(self, other)
    952         raise UnitConversionError(
--> 953             "'{0!r}' is not a scaled version of '{1!r}'".format(self, other))
    954 

UnitConversionError: 'Unit("km / s")' is not a scaled version of 'Unit(dimensionless)'

During handling of the above exception, another exception occurred:

UnitConversionErrorTraceback (most recent call last)
~/project/venv/lib/python3.6/site-packages/astropy/units/quantity.py in __float__(self)
   1079         try:
-> 1080             return float(self.to_value(dimensionless_unscaled))
   1081         except (UnitsError, TypeError):

~/project/venv/lib/python3.6/site-packages/astropy/units/quantity.py in to_value(self, unit, equivalencies)
    711                 # Short-cut failed; try default (maybe equivalencies help).
--> 712                 value = self._to_value(unit, equivalencies)
    713             else:

~/project/venv/lib/python3.6/site-packages/astropy/units/quantity.py in _to_value(self, unit, equivalencies)
    642         return self.unit.to(unit, self.view(np.ndarray),
--> 643                             equivalencies=equivalencies)
    644 

~/project/venv/lib/python3.6/site-packages/astropy/units/core.py in to(self, other, value, equivalencies)
    988         else:
--> 989             return self._get_converter(other, equivalencies=equivalencies)(value)
    990 

~/project/venv/lib/python3.6/site-packages/astropy/units/core.py in _get_converter(self, other, equivalencies)
    919 
--> 920             raise exc
    921 

~/project/venv/lib/python3.6/site-packages/astropy/units/core.py in _get_converter(self, other, equivalencies)
    905             return self._apply_equivalencies(
--> 906                 self, other, self._normalize_equivalencies(equivalencies))
    907         except UnitsError as exc:

~/project/venv/lib/python3.6/site-packages/astropy/units/core.py in _apply_equivalencies(self, unit, other, equivalencies)
    889             "{0} and {1} are not convertible".format(
--> 890                 unit_str, other_str))
    891 

UnitConversionError: 'km / s' (speed) and '' (dimensionless) are not convertible

During handling of the above exception, another exception occurred:

TypeErrorTraceback (most recent call last)
<ipython-input-10-6f08e71ebd86> in <module>
      1 plt.figure()
----> 2 plt.hist(v, bins='auto', histtype="step")
      3 plt.xlabel("Velocity (km/s)")
      4 plt.ylabel("N")

~/project/venv/lib/python3.6/site-packages/matplotlib/pyplot.py in hist(x, bins, range, density, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, normed, data, **kwargs)
   2634         align=align, orientation=orientation, rwidth=rwidth, log=log,
   2635         color=color, label=label, stacked=stacked, normed=normed,
-> 2636         **({"data": data} if data is not None else {}), **kwargs)
   2637 
   2638 

~/project/venv/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, data, *args, **kwargs)
   1587     def inner(ax, *args, data=None, **kwargs):
   1588         if data is None:
-> 1589             return func(ax, *map(sanitize_sequence, args), **kwargs)
   1590 
   1591         bound = new_sig.bind(ax, *args, **kwargs)

~/project/venv/lib/python3.6/site-packages/matplotlib/axes/_axes.py in hist(self, x, bins, range, density, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, normed, **kwargs)
   6723             # make sure we have seen at least one non-nan and finite
   6724             # value before we reset the bin range
-> 6725             if not np.isnan([xmin, xmax]).any() and not (xmin > xmax):
   6726                 bin_range = (xmin, xmax)
   6727 

~/project/venv/lib/python3.6/site-packages/astropy/units/quantity.py in __float__(self)
   1080             return float(self.to_value(dimensionless_unscaled))
   1081         except (UnitsError, TypeError):
-> 1082             raise TypeError('only dimensionless scalar quantities can be '
   1083                             'converted to Python scalars')
   1084 

TypeError: only dimensionless scalar quantities can be converted to Python scalars
TypeError: only dimensionless scalar quantities can be converted to Python scalars

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions