-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Improve formatting of imshow() cursor data when a colorbar exists. #12459
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
4481b0c
to
02a0455
Compare
lib/matplotlib/cbook/__init__.py
Outdated
|
||
Only handles fully math and fully non-math strings. | ||
""" | ||
if s[:1] == s[-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.
Any reason not to write if s[0] == s[-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.
That was to handle empty strings as well (which do occur here if e.g. you disable offsettexts), but I realized this would still give the wrong result with s = "$". So I added an explicit check on len(s) instead.
02a0455
to
1c9dbc5
Compare
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.
Looks good; needs tests, and an API note I think.
1c9dbc5
to
4dda553
Compare
added whatsnew (it's not an API change) and test |
When a colorbar exists, use its formatter to format cursor data. For example, after ``` imshow([[10000, 10001]]); colorbar() ``` currently the cursor data on either pixel is rendered as 1e4, but after this patch it becomes 0.0+1e4 / 1.0+1e4, or 10000.0 / 10001.0 if `rcParams["axes.formatter.useoffset"]` is set to False. (Even though the version with the offset text may not be the most esthetic, it's clearly more informative than the current behavior...) It would be nice if this worked even for ScalarMappables that don't have a colorbar; this may include extracting the Formatter selection code out of the colorbar code into something generally applicable to ScalarMappables, or just generating a hidden colorbar "on-the-fly" if needed just for the purpose of getting its Formatter.
0373d1b
to
3b37b08
Compare
todo: confirm that nothing horrible happens with boundarynorms. |
Actually one can just try with |
When a colorbar exists, use its formatter to format cursor data.
For example, after
currently the cursor data on either pixel is rendered as 1e4, but after
this patch it becomes 0.0+1e4 / 1.0+1e4, or 10000.0 / 10001.0 if
rcParams["axes.formatter.useoffset"]
is set to False. (Even thoughthe version with the offset text may not be the most esthetic, it's
clearly more informative than the current behavior...)
It would be nice if this worked even for ScalarMappables that don't
have a colorbar; this may include extracting the Formatter selection
code out of the colorbar code into something generally applicable to
ScalarMappables, or just generating a hidden colorbar "on-the-fly" if
needed just for the purpose of getting its Formatter.
PR Summary
PR Checklist