Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behaviour of float vs. str valued linewidth kwarg when saving plots as ps or eps. #4306

Closed
kirnis opened this issue Apr 2, 2015 · 6 comments

Comments

@kirnis
Copy link

kirnis commented Apr 2, 2015

There is a minor discrepancy in the behaviour of the linewidth kwarg between producing plots in the pyplot window and saving these plots into a file. According to the matplotlib documentation this kwarg accepts a float value. But I noticed that you can also give the value as a string and the plot works just fine. In other words, both of

plot(x,y,linewidth=1.5) and
plot(x,y,linewidth='1.5')

work and produce identical line plots of y vs. x. However, if the latter option of string valued linewidth is used, it is not possible to save the plot into ps or eps files. Instead the pyplot window gives the error message

"float argument required, not str"

without indicating where exactly the error occurred. This is inconsistent behaviour. You should either be able to use string valued linewidth kwargs when saving plots into ps or eps files or using the string values should be entirely forbidden here.

@tacaswell tacaswell added this to the unassigned milestone Apr 2, 2015
@tacaswell
Copy link
Member

It is more surprising that it works with the other backends.

Why are you passing in linewidth as a string? I don't the documentation claims anywhere that passing strings should work....

@kirnis
Copy link
Author

kirnis commented Apr 5, 2015

I was also surprised about the behaviour. The discovery came from having passed plot symbols and colours as strings and being too lazy to check the documentation for the correct way to pass linewidth. Since the string values for linewidth kind of worked at first I didn't notice my error till trying to save the plots. In some other case there might have been a delay of months before having the need to produce the plots into files and noticing that something had gone wrong.

I was left hoping that the unsupported string values of linewidth would be made to result in an error earlier on so that this kind of lazy programming wouldn't bite others.

@OceanWolf
Copy link
Contributor

Why don't we do it the other way around, just do foo = float(foo) or something if needed, it feels more pythonic that way, quack-quack.

@efiring
Copy link
Member

efiring commented Apr 5, 2015

@OceanWolf are you suggesting that a string should be accepted? I don't agree. Things that fundamentally are numbers should be supplied as numbers. A string doesn't quack like a number. Accepting a string here seems, to me, more perlish than pythonic.

@OceanWolf
Copy link
Contributor

@efiring I did mean to suggest that, yes, float('3.3') == float(3.3), so in that sense they quack the same, on the otherhand float('foo') raises a ValueError: could not convert string to float: foo, which seems like a good enough error message to me.

I don't really mind either way, whatever you decide.

@tacaswell
Copy link
Member

@kirnis We have patched this to work, but please change your code to pass in floats!

fariza pushed a commit to fariza/matplotlib that referenced this issue May 15, 2015
Explicitly cast linewidth to a float in `set_linewidth` methods
of `Line2D` and `Patch`

Closes matplotlib#4306
@QuLogic QuLogic modified the milestones: unassigned, v1.5.0 Jul 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants