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

Check for float values for min/max values to ax{v,h}line#17822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
timhoffm merged 2 commits intomatplotlib:masterfromdstansby:float-check
Jul 27, 2020

Conversation

dstansby
Copy link
Member

Fixes#12198. This now errors if a non-float value is provided for xmin/xmax or ymin/ymax to ax{v,h}{line,span}. This should get an API change or a what's new, but I'm not sure which, could someone advise?

@tacaswell
Copy link
Member

I don't think checking for the ability to cast to float is enough, we need to make sure that the data will not select a converter.

@dstansby
Copy link
MemberAuthor

I foundmatplotlib.units._is_natively_supported, which I think does the correct job here.

@jklymak
Copy link
Member

On master

importmatplotlib.pyplotaspltimportmatplotlib.datesasmdatesline=plt.axvline(x=.5,ymin=mdates.num2date(1),ymax=mdates.num2date(1.05))line.set_clip_on(False)plt.show()

already errors out:

Traceback (most recent call last):  File "./testAXvline.py", line 3, in <module>    line = plt.axvline(  File "/Users/jklymak/matplotlib/lib/matplotlib/pyplot.py", line 2464, in axvline    return gca().axvline(x=x, ymin=ymin, ymax=ymax, **kwargs)  File "/Users/jklymak/matplotlib/lib/matplotlib/axes/_axes.py", line 917, in axvline    self.add_line(l)  File "/Users/jklymak/matplotlib/lib/matplotlib/axes/_base.py", line 1977, in add_line    self._update_line_limits(line)  File "/Users/jklymak/matplotlib/lib/matplotlib/axes/_base.py", line 1999, in _update_line_limits    path = line.get_path()  File "/Users/jklymak/matplotlib/lib/matplotlib/lines.py", line 1011, in get_path    self.recache()  File "/Users/jklymak/matplotlib/lib/matplotlib/lines.py", line 658, in recache    y = _to_unmasked_float_array(yconv).ravel()  File "/Users/jklymak/matplotlib/lib/matplotlib/cbook/__init__.py", line 1298, in _to_unmasked_float_array    return np.asarray(x, float)  File "/Users/jklymak/anaconda3/envs/matplotlibdev/lib/python3.8/site-packages/numpy/core/_asarray.py", line 85, in asarray    return array(a, dtype, copy=False, order=order)TypeError: float() argument must be a string or a number, not 'datetime.datetime'(matplotlibdev)

So is the point of this PR to just make the error more explicit? If so, I don't think it needs an API change or note, because I guess that has already occurred.

@QuLogic
Copy link
Member

That specific example broke ina793bde, which is a date-specific change. Is it still true that other unit-ful values are currently broken?

@dstansby
Copy link
MemberAuthor

Yes, I think it might just be a better error now, with the following example

importmatplotlib.pyplotaspltimportastropy.unitsasufromastropy.visualizationimportquantity_supportquantity_support()fig,ax=plt.subplots()ax.scatter(1*u.m,1*u.s)ax.axhline(1*u.s,xmin=0.1*u.m)plt.show()

The error before was

Traceback (mostrecentcalllast):File"/Users/dstansby/github/matplotlib/lib/matplotlib/axis.py",line1524,inconvert_unitsret=self.converter.convert(x,self.units,self)File"/Users/dstansby/github/astropy/astropy/visualization/units.py",line102,inconvertreturn [v.to_value(unit)forvinval]File"/Users/dstansby/github/astropy/astropy/visualization/units.py",line102,in<listcomp>return [v.to_value(unit)forvinval]AttributeError:'int'objecthasnoattribute'to_value'Theaboveexceptionwasthedirectcauseofthefollowingexception:Traceback (mostrecentcalllast):File"test.py",line8,in<module>ax.axhline(1*u.s,xmin=0.1*u.m)File"/Users/dstansby/github/matplotlib/lib/matplotlib/axes/_axes.py",line847,inaxhlineself.add_line(l)File"/Users/dstansby/github/matplotlib/lib/matplotlib/axes/_base.py",line1977,inadd_lineself._update_line_limits(line)File"/Users/dstansby/github/matplotlib/lib/matplotlib/axes/_base.py",line1999,in_update_line_limitspath=line.get_path()File"/Users/dstansby/github/matplotlib/lib/matplotlib/lines.py",line1011,inget_pathself.recache()File"/Users/dstansby/github/matplotlib/lib/matplotlib/lines.py",line652,inrecachexconv=self.convert_xunits(self._xorig)File"/Users/dstansby/github/matplotlib/lib/matplotlib/artist.py",line175,inconvert_xunitsreturnax.xaxis.convert_units(x)File"/Users/dstansby/github/matplotlib/lib/matplotlib/axis.py",line1526,inconvert_unitsraisemunits.ConversionError('Failed to convert value(s) to axis 'matplotlib.units.ConversionError:Failedtoconvertvalue(s)toaxisunits: [<Quantity0.1m>,1]

And the error with this PR is

Traceback (mostrecentcalllast):File"test.py",line8,in<module>ax.axhline(1*u.s,xmin=0.1*u.m)File"/Users/dstansby/github/matplotlib/lib/matplotlib/axes/_axes.py",line834,inaxhlineself._check_no_units([xmin,xmax], ['xmin','xmax'])File"/Users/dstansby/github/matplotlib/lib/matplotlib/axes/_axes.py",line926,in_check_no_unitsraiseValueError(f"{name} must be a single scalar value, "ValueError:xminmustbeasinglescalarvalue,butgot0.1m

Copy link
Member

@jklymakjklymak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think this is an improved error message.

Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
@timhoffmtimhoffm merged commit7b574c3 intomatplotlib:masterJul 27, 2020
@dstansbydstansby deleted the float-check branchJuly 27, 2020 17:19
@QuLogic
Copy link
Member

Hmm, those exception lines are too long; I wonder whyflake8 is not complaining.

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

@QuLogicQuLogicQuLogic left review comments

@jklymakjklymakjklymak approved these changes

@timhoffmtimhoffmtimhoffm approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.4.0
Development

Successfully merging this pull request may close these issues.

axvline incorrectly tries to handle unitized ymin, ymax
5 participants
@dstansby@tacaswell@jklymak@QuLogic@timhoffm

[8]ページ先頭

©2009-2025 Movatter.jp