-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Change styling of slider widgets #19265
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
Is |
I did it that way for two reasons:
I suppose those probably don't fully justify the added complexity though |
Just tried out with using the |
I guess it would make sense to simplify by just having a single static background rect |
can we have a bigger difference in brightness for the right and left
rectangles? They are too close to easily distinguish.
…On Sat, Jan 9, 2021 at 1:25 PM Ian Hunt-Isaak ***@***.***> wrote:
I guess it would make sense to simplify by just having a single static
background rect
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#19265 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACHF6FM564N5NFWJVKOU2DSZCNTFANCNFSM4V3KRDVQ>
.
|
Fine by me. Any specific suggestions for colors? The left rectangle is currently just whatever is first in the users color cycle as it is generated by |
lib/matplotlib/widgets.py
Outdated
@@ -404,11 +424,31 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt=None, | |||
self.val = valinit | |||
self.valinit = valinit | |||
if orientation == 'vertical': | |||
self.poly = ax.axhspan(valmin, valinit, 0, 1, **kwargs) | |||
self.hline = ax.axhline(valinit, 0, 1, color=initcolor, lw=1) | |||
self.bkd = Rectangle((.25, 0), .5, 1, transform=ax.transAxes, facecolor=bkd_color) |
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.
Can we have a more telling name?
self.bkd = Rectangle((.25, 0), .5, 1, transform=ax.transAxes, facecolor=bkd_color) | |
self.track = Rectangle((.25, 0), .5, 1, transform=ax.transAxes, facecolor=bkd_color) |
seems to be the technical term.
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.
Ah that's a much better name thanks. I was struggling to find the correct term.
lib/matplotlib/widgets.py
Outdated
if event.name == 'button_press_event': | ||
self._handle.set_markeredgecolor(self._handle_color_grabbed) | ||
self._handle.set_markerfacecolor(self._handle_color_grabbed) |
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.
I'm not sure if this action helpful. If sliders have GUI feedback, it's usually already done on hovering to indicate that you have an control element under the cursor. IMHO changing the color after clicking is too late and serves no purpose.
For simplicity, I'd refrain from changing the color at all.
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.
I did this because I was copying the behavior of ipywidgets sliders without much critical thought 😬.
I have a slight preference for them changing color after selection vs not but I'll happily remove it when I next push here. Reducing the number of new configuration kwargs seems like a good thing.
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.
That said changing as you mouse over the axes could be nice. I imagine this could be accomplished by using axes_enter_event
and axes_leave_event
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.
ipywidgets use color to indicate focus (e.g. which control reacts to the keyboard). I don't think our widgets have a concept of focus.
If you want an effect, see also Button
for a mouse-over effect. Though here you might want to additionally check if the cursor is on the knob.
We could also say that the "active" color is the same color as the bar (C0). That would still save us the extra argument. One can always add more configurability later when the need arises.
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.
ipywidgets use color to indicate focus (e.g. which control reacts to the keyboard). I don't think our widgets have a concept of focus.
aaah. I'm fully convinced by this, I'll remove it as it's bad to indicate something that is isn't there.
I like the lightgrey. Works very well.
Another thing to be aware of is that while white (or rather transparent on
top of the standard gui window color, which is white) is the default, there
are people who change these defaults or are embedding matplotlib in other
apps. I haven't looked at the changes yet. but how easy is it going to be
to tweak these colors?
…On Sat, Jan 9, 2021 at 1:42 PM Ian Hunt-Isaak ***@***.***> wrote:
How about lightgrey? The bottom slider here:
[image: image]
<https://user-images.githubusercontent.com/10111092/104106018-752b5e00-5280-11eb-94af-805d1e5383e3.png>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#19265 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACHF6FWSBPTYLU2HN6OBYTSZCPQVANCNFSM4V3KRDVQ>
.
|
The track color has a |
Also: heads up to @t-makaro you may be interested in this on account of animatplot. |
cc44f7d
to
b335716
Compare
Notes | ||
----- | ||
Additional kwargs are passed on to ``self.poly`` which is the | ||
`~matplotlib.patches.Rectangle` that draws the slider knob. See the | ||
`.Rectangle` documentation for valid property names (``facecolor``, | ||
`~matplotlib.patches.Polygon` that draws the slider knob. See the |
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.
https://matplotlib.org/devdocs/api/_as_gen/matplotlib.pyplot.axvspan.html
ax{h,v}span
returns a Polygon
not a Rectangle
patch.
rebased + squashed and updated the GIF on the first post. |
I've also reworked the Should I include that here or add that as a followup PR? |
lib/matplotlib/widgets.py
Outdated
) | ||
ax.add_patch(self.track) | ||
self.poly = ax.axhspan(valmin, valinit, .25, .75, **kwargs) | ||
self.hline = ax.axhline(valinit, .25, .75, color=initcolor, lw=1) |
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.
self.hline = ax.axhline(valinit, .25, .75, color=initcolor, lw=1) | |
self.hline = ax.axhline(valinit, .15, .85, color=initcolor, lw=1) |
The init line extends one pixel more to the right (or bottom for horizontal sliders), which looks a bit awkward.
I suspect that the effect comes from different to-pixel mappings of lines and rectangles (lines render including both end points; i.e. two lines ending in the same point would draw on top of each other. But rectangles are designed to not overlap if they are side-by-side). - This is just speculation, but I've checked and excluded some other possible reasons (capstyle and snapping).
The cheap solution to get away with a reasonably looking init marker is to let it extend slightly on both sides. The pixel difference is still there, but 2 vs. 3 is less noticeable than 0 vs. 1.
Same for horizontal 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.
I recommend a separate PR, because that makes reviewing simpler. (The longer a PR is, the less likely somebody takes the time to review. And the relation is non-linear. 😝 ) |
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.
There are more warnings causing the doc build to fail due to #19415.
Please rebase so that that fix is picked up.
edgecolor color '.75' The edgecolor of the slider handles. | ||
size int 10 The size of the slider handles in points. | ||
========= ===== ======= ========================================= | ||
Other values will be transformed as marker{foo} and passed to the |
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.
Other values will be transformed as marker{foo} and passed to the | |
Other values will be transformed as marker{foo} and passed to the |
1d555c0
to
24ff1a9
Compare
rebased - thanks for the heads up |
Hi, I think I've addressed all of the requested revisions. Is it ok to remove the Well, perhaps with the exception of the issue of the red line offset #19265 (comment) though I don't think that that is waiting on me |
Yes. (Basically whenever you consider you handled the revision requests.) |
Actually, I was waiting on a code change here. IMHO uneven extensions are at least better than one side ending exactly on the line and the other going beyond. Since we cannot be pixel-perfect, the default lines should be a bit wider than the bar. At a closer look, you are right that .15, .85 work for the vertical slider but not very well for the horizontal slider. I'd be ok if you tune the horizontal slider by using .2, .9 and adding a comment on that. Interestingly, this asymmetric axes coordinates result in a symmetric extension of the line. It seems that for some reason, horizontal and vertical coordinate to pixel mapping is different. If somebody is interested, you're welcome to dig in this. But just using the empirical values is good enough for now. In the worst case we accidentially fix the coordinates and the line will move one pixel again, but that would also not be the end of the world. |
ack! sorry for misinterpreting.
Oh that's wild. Thanks for finding those values! I've gone with the simple solution for now. |
Milestoning as this is ready modulo the what's new entry, and we should not miss the next minor release. |
@timhoffm sorry I stalled out here. I was asking on gitter awhile ago about how to show the style in the whats new and @tacaswell expressed concern that these changes are somewhat backwards incompatible as there is not easy way to get the old style back. |
Hm ok, maybe that's to be discussed on the dev call. OTOH, this is essentially UI element style change, which I consider less invasive than a plot style change (Any OS I'm using is changing its UI under me all the time). |
Discussed in the dev call today: Widget apperance is not considered stable API. We can change this in minor releases. This shoud still get a "What's new" entry. |
6b4cbc8
to
91c2e4e
Compare
91c2e4e
to
56ae7d3
Compare
Goal is to add a clear handle for the user to grab and to provide visual feedback via color change of when the slider has been grabbed. Simplify slider background rectangles rename bkd -> track + change default color to lightgrey lint remove facecolor from snap demo example Don't change handle color on grab. correct errors in slider docstrings Co-Authored-By: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Co-Authored-By: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Co-Authored-By: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
56ae7d3
to
f5dcedd
Compare
Rebased to pick up fix for failing tests #20488 Rendered What's new Entry here: https://61099-1385122-gh.circle-artifacts.com/0/doc/build/html/users/next_whats_new/slider_styling.html |
Any other widget users want to bless this? Please squash commits unless @ianhi thinks they are all meaningful. |
Maybe @snowtechblog @redeboer @t-makaro
They are not - I can squash |
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.
Not an expert on widgets, but I think @timhoffm gave this a through review.
PR Summary
Closes: #19256
Updates the styling of the slider widgets to look like this:

poly
patch smallerwill change color when grabbedAxes
and indicate the length of the slider with rectangle patch.PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).