Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
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 writeif 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.
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.
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 afterthis 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'sclearly more informative than the current behavior...)It would be nice if this worked even for ScalarMappables that don'thave a colorbar; this may include extracting the Formatter selectioncode out of the colorbar code into something generally applicable toScalarMappables, or just generating a hidden colorbar "on-the-fly" ifneeded just for the purpose of getting its Formatter.
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