-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Fix multiple zero labels when using SymLogNorm #10129
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
Fix multiple zero labels when using SymLogNorm #10129
Conversation
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.
This seems OK to me. But isn't the root problem that there are two zeros returned by the Locator? Can't we just remove the duplicate entry from the Locator?
matplotlib/lib/matplotlib/ticker.py Line 2215 in 64874e5
matplotlib/lib/matplotlib/ticker.py Line 2353 in 64874e5
|
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.
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. |
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.
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_values
shows 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