Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 16 commits into from
Oct 8, 2018

Conversation

williamjameshandley
Copy link
Contributor

@williamjameshandley williamjameshandley commented Mar 9, 2018

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

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

…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.
@anntzer
Copy link
Contributor

anntzer commented Mar 9, 2018

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.
@jklymak
Copy link
Member

jklymak commented Mar 12, 2018

This seems reasonable to me. But, I think this needs a test in tests/test_widgets.py (or a good reason its not possible).

@jklymak jklymak added this to the v3.0 milestone Mar 12, 2018
@williamjameshandley
Copy link
Contributor Author

Tests added and passed

@@ -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'
Copy link
Member

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.

Copy link
Member

@timhoffm timhoffm left a 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.

@@ -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'}:
Copy link
Member

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.

jklymak
jklymak previously requested changes Jul 9, 2018
Copy link
Member

@jklymak jklymak left a 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

@williamjameshandley
Copy link
Contributor Author

Added what's new to doc/users/whats_new.rst, since doc/users/next_whats_new/ is now empty.

@tacaswell tacaswell modified the milestones: v3.0, v3.1 Jul 15, 2018
@jklymak
Copy link
Member

jklymak commented Sep 19, 2018

Ping us when this passes CI!

@williamjameshandley
Copy link
Contributor Author

@jklymak CI passed

@jklymak
Copy link
Member

jklymak commented Oct 6, 2018

Sorry one more hoop. Can you merge the commits into one commit?

Copy link
Member

@timhoffm timhoffm left a 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.


self.valfmt = valfmt
ax.set_yticks([])
ax.set_xlim((valmin, valmax))
if orientation is 'vertical':
Copy link
Member

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.

@timhoffm
Copy link
Member

timhoffm commented Oct 7, 2018

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.

Copy link
Member

@timhoffm timhoffm left a 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.

@timhoffm timhoffm merged commit 820bea6 into matplotlib:master Oct 8, 2018
@timhoffm
Copy link
Member

timhoffm commented Oct 8, 2018

Thanks for your contribution and congratulations to your first successful PR to matplotlib! Hope to see you back somewhen. 😄

timhoffm added a commit to timhoffm/matplotlib that referenced this pull request Oct 8, 2018
anntzer added a commit that referenced this pull request Oct 8, 2018
Rollback erronous commit to whats_new.rst from #10746
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants