Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Better deal with Numpy array subclasses in methods other than plot and scatter #5896

Closed
@astrofrog

Description

@astrofrog

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp