-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Improve default formatter for Slider values. #17077
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
Using a ScalarFormatter works both for very small and for very large values. We try to keep a user-configured ScalarFormatter if there's already one (not that this was likely at all given that the formatter is otherwise discarded by the call to `set_x/yticks([])`).
axis = ax.xaxis | ||
|
||
self.valfmt = valfmt | ||
self._fmt = axis.get_major_formatter() |
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.
Is this attribute is introduced here? If so, let's call it
self._fmt = axis.get_major_formatter() | |
self._formatter = axis.get_major_formatter() |
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.
fmt
for format
(ter) is a pretty standard abbreviation, and this avoids an awkward linebreak a bit later which also helps from a legibility PoV. OTOH I don't really want to argue too much over this so if you are sure you prefer _formatter, let me know and I'll do the change (yes, it's a new attribute, so we can call it however we want).
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.
If I see fmt
I expand to format
in my mind, but I do not expand to formatter
. OTOH, this isn't really a big deal here.
|
You get to write that API change (edit: API extension) :-) |
Lets go ahead and merge as an improvement, but maybe @ImportanceOfBeingErnest suggestion is a good one for a follow up? |
else: | ||
_, s, _ = self._fmt.format_ticks([self.valmin, val, self.valmax]) | ||
# fmt.get_offset is actually the multiplicative factor, if any. | ||
return s + self._fmt.get_offset() |
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 will result in 3e-8 to be shown as 31e-8.
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.
oops, I had axes.formatter.usemathtext
in my rcdefaults, we just need to force that here...
Using a ScalarFormatter works both for very small and for very large
values. We try to keep a user-configured ScalarFormatter if there's
already one (not that this was likely at all given that the formatter
is otherwise discarded by the call to
set_x/yticks([])
).See https://discourse.matplotlib.org/t/matplotlib-slider-labels-stop-responding-with-very-small-numbers/21064/1 for an example of user confused by the default format string.
No tests, but one can try with e.g.
PR Summary
PR Checklist