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

Sanitize input for plotItem.showGrid (was documentation fix for plotItem.showGrid alpha setting) #1809

Merged
merged 2 commits into from
Jun 2, 2021

Conversation

NilsNemitz
Copy link
Contributor

Looking through some issues, I came across #1484:

setting plotItem.showGrid(True, True, alpha=0.5) raises TypeError: setValue(self, int): argument 1 has unexpected type 'numpy.float64'

This is a documentation error:
The expected alpha value does not range from 0.0 to 1.0 (as in the current docstring), but instead ranges from 0-255.

This PR updates the docstring to show that and adds a cast to int to avoid raising an error.
The alpha=0.5 value in the original report will no longer result in an error and draw an invisible, fully transparent grid.
Setting alpha=127 creates the desired half-transparent grid.

So this should close #1484.

@ixjlyons
Copy link
Member

ixjlyons commented May 30, 2021

I don't think this is a documentation error actually. The slider goes from 0 to 255:

<widget class="QSlider" name="gridAlphaSlider">
<property name="maximum">
<number>255</number>

So using alpha as a [0, 1] scaler for the max of the slider is doing what's intended, it's just that QSlider.setValue takes an int type. setValue(int(v)) should suffice.

edit: Also I should point out the proposed fix would be a change in behavior, and I actually don't see the error in #1484 -- I'm not sure if there's a platform-specific thing going on with type strictness or what

@NilsNemitz
Copy link
Contributor Author

True.

@ixjlyons , this update restores the 0-1 range and just adds the cast to int.

@NilsNemitz NilsNemitz changed the title documentation fix for plotItem.showGrid alpha setting Sanitize input for plotItem.showGrid (was documentation fix for plotItem.showGrid alpha setting) May 30, 2021
Copy link
Member

@ixjlyons ixjlyons left a comment

Choose a reason for hiding this comment

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

Looks good to me. The comment there is helpful too 👍

@j9ac9k
Copy link
Member

j9ac9k commented Jun 2, 2021

LGTM, merging. Thanks @NilsNemitz !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Int conversion issues when showing plot grid
3 participants