Fix multiple zero labels when using SymLogNorm#10129
Fix multiple zero labels when using SymLogNorm#10129dstansby merged 2 commits intomatplotlib:masterfrom
Conversation
|
matplotlib/lib/matplotlib/ticker.py Line 2215 in 64874e5 matplotlib/lib/matplotlib/ticker.py Line 2353 in 64874e5 |
anntzer
left a comment
There was a problem hiding this comment.
The strategy of this PR can't work. If you run e.g. examples/pyplots/pyplot_scales.py with this PR applied, and move or zoom the symlog axes, the label at 0 disappears (because it is never redrawn).
I believe that @jklymak's idea is the correct approach.
|
That’s a great point. I’ll spend some more time in the locator and the linear approximation around zero and see if there’s a good way to ensure only a single zero value.
…On Dec 29, 2017, 2:14 PM -0600, Antony Lee ***@***.***>, wrote:
@anntzer requested changes on this pull request.
The strategy of this PR can't work. If you run e.g. examples/pyplots/pyplot_scales.py with this PR applied, and move or zoom the symlog axes, the label at 0 disappears (because it is never redrawn).
I believe that @jklymak's idea is the correct approach.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
fd130c1 to
b26b598
Compare
b26b598 to
7fe5e4e
Compare
|
👍 That makes sense and looks like a reasonable fix. Could you add a test? I suspect creating a symlog axis and then asserting that there is only 0 zero label it in is the best approach (no need for an image test). The OP example is maybe a bit complex to trigger this, but as a last resort would be ok to use a test. |
tacaswell
left a comment
There was a problem hiding this comment.
Fix looks good, just needs a test.
Anyone can dismiss this when a test is added.
Dismissing @tacaswell review as test now added per his wishes
|
Just for completeness, the test is: from matplotlib import pyplot as plt
import matplotlib as mpl
fig, axes = plt.subplots(1, 2, True, True)
for i, ax in enumerate(axes):
im = ax.imshow([[0]], norm=mpl.colors.SymLogNorm(1e-5, vmin=-1, vmax=1))
cb = plt.colorbar(im, ax=ax)
# Clean up the labels
zero_labelled = False
for label in cb.ax.yaxis.get_ticklabels():
if label.get_text() == r'$\mathdefault{0}$':
if zero_labelled:
label.set_visible(False)
zero_labelled = True
plt.show() |
|
Thanks a lot @Raab70! |
PR Summary
Use the previously unused position of a tick label to ensure that only a single zero label is rendered when using SymLogNorm. I store the first time a zero label is encountered and return blanks for all following zeros. The documentation on theticker.SymmetricalLogLocator.tick_valuesshows how these multiple zeros come to be through the linear approximation near zero.As per discussion below I have taken a different approach, trying to fix the root cause of the problem in the locator (
ticker.SymmetricalLogLocator.tick_values) so that the extra zero ticks are never created in the first place.Fixes #10122
PR Checklist