| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
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. |
Sorry, something went wrong.
|
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.). |
Sorry, something went wrong.
|
Can’t we refactor that somehow? Seems quite hacky that you have to create a colorbar to make this work. |
Sorry, something went wrong.
|
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. |
Sorry, something went wrong.
|
I think the relevant code for matching up the Norm and Formatter is just: matplotlib/lib/matplotlib/colorbar.py Lines 395 to 402 in f77c979 Can't we just make colorbar._get_formatter_(norm) and call here and in colorbar? |
Sorry, something went wrong.
|
No, you also need to have an underlying axes that sets the locs for the formatter (that's list(ax.yaxis.iter_ticks()) in this PR), otherwise the formatter can't format the values (https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/ticker.py#L562). |
Sorry, something went wrong.
|
You are right, but that seems quite unfortunate. I think most places where self.axis.get_view_internal() is called could be changed to min/max(self.locs) if self.axis is None. Then all you'd have to do is manually set the view limits. I understand why we'd generally want to defer to the viewlimits, but its a shame to not allow the formatters to be independent of an axis if possible. How does this work with lognorms anyways? The log formatter returns empty strings a lot of the time. |
Sorry, something went wrong.
|
Oooh, does Formatter.create_dummy_axis help? |
Sorry, something went wrong.
|
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? |
Sorry, something went wrong.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
fmt = 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: Scalar: 20
10: $\mathdefault{10^{1}}$
20:
100: $\mathdefault{10^{2}}$
200:
As above, not sure you even ever want to LogFormatter, but maybe I'm misunderstanding how this works... |
Sorry, something went wrong.
|
@jklymak Actually, you need to call fmt.axis.set_view_interval (instead of fmt.set_locs). import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
fmt = mticker.ScalarFormatter()
fmt.create_dummy_axis()
fmt.axis.set_view_interval(0.01, 1000)
print('Scalar:', fmt(20))
fmt = mticker.LogFormatterSciNotation()
fmt.create_dummy_axis()
fmt.axis.set_view_interval(0.01, 1000)
print('10:', fmt(10))
print('20:', fmt(20))
print('100:', fmt(100))
print('200:', fmt(200))
gives Scalar:
False None 1.0
10: $\mathdefault{10^{1}}$
False None 2.0
20: $\mathdefault{2\times10^{1}}$
False None 1.0
100: $\mathdefault{10^{2}}$
False None 2.0
200: $\mathdefault{2\times10^{2}}$
(I guess I should add a \times -> x in strip_math... now added to #12459) @timhoffm Then we just fallback on the old label string (which is much less useful): #12459 protects everything under a if self.colorbar anyways. |
Sorry, something went wrong.
|
I still think we should create a dummy axis, not colorbar... Formatter.create_dummy_axis should be made to work, but I admit I haven't wrestled with it yet. |
Sorry, something went wrong.
|
Perhaps(??) things will become easier after the followup PRs after format_ticks get handled. |
Sorry, something went wrong.
... if no colorbar exists yet.
| Back | FazBrowse Home | New Git URL |
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