Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
Create a hidden colorbar on-the-fly to format imshow cursor data if no colorbar exists yet.#12473
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
jklymak commentedOct 10, 2018
Why don’t you just add a formatter to the artist? This API May be preferable anyways to using the colorbar formatter though that could be the default. |
anntzer commentedOct 10, 2018
Because the correct Formatter depends on the Normalization subclass being used, and that logic currently only exists in the colorbar code (nowhere else does it say that LogNorm should use LogFormatter, etc.). |
jklymak commentedOct 10, 2018
Can’t we refactor that somehow? Seems quite hacky that you have to create a colorbar to make this work. |
anntzer commentedOct 10, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
The relationship between norms, scales, colorbars, locators and formatters has been discussed to death (although in a slightly deconstructed fashion) a few times e.g. in#7294 (#7294 (comment),#7294 (comment), ...); TLDR: I think Norms and Scales should be the same thing. |
jklymak commentedOct 10, 2018
I think the relevant code for matching up the Norm and Formatter is just: matplotlib/lib/matplotlib/colorbar.py Lines 395 to 402 inf77c979
Can't we just make |
anntzer commentedOct 10, 2018
No, youalso need to have an underlying axes that sets the locs for the formatter (that's |
jklymak commentedOct 10, 2018
You are right, but that seems quite unfortunate. I think most places where How does this work with lognorms anyways? The log formatter returns empty strings a lot of the time. |
jklymak commentedOct 10, 2018
Oooh, does |
timhoffm commentedOct 10, 2018
Didn't have time to look at the code, but I agree with@jklymak that this sounds extremely hacky. If it's not simple to refactor: What happens if we do not implement this? Does something crash or do we just not have the output displayed? |
jklymak commentedOct 11, 2018
importnumpyasnpimportmatplotlib.pyplotaspltimportmatplotlib.tickerasmtickerfmt=mticker.ScalarFormatter()fmt.create_dummy_axis()fmt.set_locs([0.01,1000])print('Scalar:',fmt(20))fmt=mticker.LogFormatterSciNotation()fmt.create_dummy_axis()fmt.set_locs([0.01,1000])print('10:',fmt(10))print('20:',fmt(20))print('100:',fmt(100))print('200:',fmt(200)) Gives: As above, not sure you even ever want to LogFormatter, but maybe I'm misunderstanding how this works... |
anntzer commentedOct 11, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@jklymak Actually, you need to call fmt.axis.set_view_interval (instead of fmt.set_locs). gives (I guess I should add a @timhoffm Then we just fallback on the old label string (which is much less useful):#12459 protects everything under a |
f33913f to56a5cc9Comparejklymak commentedFeb 26, 2019
I still think we should create a dummy axis, not colorbar... |
anntzer commentedFeb 26, 2019
Perhaps(??) things will become easier after the followup PRs after format_ticks get handled. |
... if no colorbar exists yet.
anntzer commentedJan 2, 2022
Superseded by#20949. |
PR Summary
Followup to#12459, which also works when no colorbar exists. Adds a second commit on top of#12459.
Made as a separate PR as it's a bit an ugly hack (optimally we'd factor out the formatter selection) but still proposing it as I think the behavior is quite nice.
I don't think it'd be a performance issue as we don't actually draw() the hidden figure -- it doesn't even have a renderer attached to it.
PR Checklist