Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
Closed
Labels
Milestone
Description
Theplot andscatter methods now deal nicely with Numpy array sub-classes, such as Astropy quantities (which have attached units):
In [1]:fromastropyimportunitsasuIn [2]:importmatplotlib.pyplotaspltIn [3]:fig=plt.figure()In [4]:ax=fig.add_subplot(1,1,1)In [5]:x= [1,2]*u.mIn [6]:y= [3,4]*u.mIn [7]:ax.plot(x,y)Out[7]: [<matplotlib.lines.Line2Dat0x107f00048>]In [8]:ax.scatter(x,y)Out[8]:<matplotlib.collections.PathCollectionat0x107f00ba8>
However, other methods such asaxhline andaxvline do not:
In [9]:z=4*u.mIn [10]:ax.axhline(z)---------------------------------------------------------------------------UnitsErrorTraceback (mostrecentcalllast)<ipython-input-10-39d10b51e434>in<module>()---->1ax.axhline(z)/Users/tom/miniconda3/envs/production35/lib/python3.5/site-packages/matplotlib/axes/_axes.pyinaxhline(self,y,xmin,xmax,**kwargs)744self._process_unit_info(ydata=y,kwargs=kwargs)745yy=self.convert_yunits(y)-->746scaley= (yy<ymin)or (yy>ymax)747748trans=self.get_yaxis_transform(which='grid')/Users/tom/miniconda3/envs/production35/lib/python3.5/site-packages/astropy/units/quantity.pyin__array_prepare__(self,obj,context)344"argument is not a quantity (unless the "345"latter is all zero/infinity/nan)"-->346 .format(function.__name__))347exceptTypeError:348# _can_have_arbitrary_unit failed: arg could not be comparedUnitsError:Canonlyapply'less'functiontodimensionlessquantitieswhenotherargumentisnotaquantity (unlessthelatterisallzero/infinity/nan)
It would be nice to try and make these methods also support Numpy array sub-classes.