-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Adjusted matplotlib.widgets.Slider to have optional vertical orientatation #10746
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
Conversation
…ion. The slider widget now takes an optional argument (orientation) with values 'h' or 'v, which defaults to 'h'. Argument checking is in keeping with the existing code, and the actual changes to the source are minimal, replacing hspans, hlines and xdata with a if switch to vspans and vlines and ydata.
Probably should be 'horizontal'/'vertical'. Longer, but consistent with the rest of the library. |
I forgot that I had not yet installed pyflakes and pylint on my new system, so my vim syntax checker didn't pick it up.
This seems reasonable to me. But, I think this needs a test in |
Tests added and passed |
lib/matplotlib/widgets.py
Outdated
@@ -309,6 +310,10 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt='%1.2f', | |||
valstep : float, optional, default: None | |||
If given, the slider will snap to multiples of `valstep`. | |||
|
|||
orientation : str, optional, default: 'horizontal' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Canonical numpydoc recommends curly braces if there is a limited list of choices. The first is implicitly the default:
orientation : {'horizontal', 'vertical'}
The orientation of the slider.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also note for the future, that you don't have to make a new commit for every change. You can simply amend and force-push the last commit by:
git commit --amend --no-edit
git push origin [yourbranch] --force
This helps in keeping the relevant changes of a feature together in one or few semantically chosen commits and results in a cleaner more readable history.
lib/matplotlib/widgets.py
Outdated
@@ -324,6 +328,11 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt='%1.2f', | |||
if slidermax is not None and not hasattr(slidermax, 'val'): | |||
raise ValueError("Argument slidermax ({}) has no 'val'" | |||
.format(type(slidermax))) | |||
if orientation not in {'horizontal', 'vertical'}: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While it's technically correct to use a set here, lists are the more common choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a whats-new entry
6391c5e
to
05ea737
Compare
05ea737
to
a70c21d
Compare
Added what's new to |
Ping us when this passes CI! |
@jklymak CI passed |
Sorry one more hoop. Can you merge the commits into one commit? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also while you're at it, I'd prefer that you change the above-mentioned value check from set to list: if orientation not in {'horizontal', 'vertical'}
-> if orientation not in['horizontal', 'vertical']
. That's much more common and thus easier to understand for the reader.
lib/matplotlib/widgets.py
Outdated
|
||
self.valfmt = valfmt | ||
ax.set_yticks([]) | ||
ax.set_xlim((valmin, valmax)) | ||
if orientation is 'vertical': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please compare strings with ==
not with is
.
Note: No need to "merge the commits into one commit" (technically that's called squash). We can now do this conveniently ourselves since github offers a "Squash and merge" button. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is just a smoke test that the orientation attribute is accepted. It does not actually test the behavior. However, that's a bit more complicated. This is good enough for now.
Thanks for your contribution and congratulations to your first successful PR to matplotlib! Hope to see you back somewhen. 😄 |
Rollback erronous commit to whats_new.rst from #10746
The slider widget now takes an optional argument (orientation) with
values 'h' or 'v, which defaults to 'h'.
Argument checking is in keeping with the existing code, and the actual
changes to the source are minimal, replacing hspans, hlines and xdata with a
if switch to vspans and vlines and ydata.
Inspired by https://stackoverflow.com/questions/25934279/add-a-vertical-slider-with-matplotlib
PR Summary
PR Checklist