-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
DOC: MaxNLocator and contour/contourf doc update (replaces #16428) #16534
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
DOC: MaxNLocator and contour/contourf doc update (replaces #16428) #16534
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.
I do not think this documentation change is correct, and if it is it is showing a major bug in the locator code.
Per #16428 (comment) I think the N
needs to be qualified to be within the view limit and that it make return additional ticks outside of the view limit.
The following test shows that it selects no more than N ticks within the view limits, inclusive on the left and exclusive on the right. It has to provide up to 2 more so that it can be used for autoscaling in "classic" mode. import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
Ntargets = np.arange(3, 20)
vmins = np.linspace(1, 10, 50)
spans = np.linspace(1, 10, 50)
shape = len(Ntargets), len(vmins), len(spans)
nticks_inside = np.zeros(shape, dtype=int)
nticks = np.zeros(shape, dtype=int)
for i, N in enumerate(Ntargets):
locator = MaxNLocator(N)
for j, vmin in enumerate(vmins):
for k, span in enumerate(spans):
vmax = vmin + span
ticks = locator.tick_values(vmin, vmax)
nticks[i, j, k] = len(ticks)
clipped = ticks[(ticks < vmax) & (ticks >= vmin)]
nticks_inside[i, j, k] = len(clipped)
print(Ntargets - nticks_inside.max(axis=-1).max(axis=-1)) Run it:
|
@tacaswell and @efiring Thanks for (patiently) explaining the point about the view limits. Pushed a change as suggested. |
Thank you, @pharshalp. |
PR Summary
closes #12729
I messed my github matplotlib repo settings (and not github doesn't recognize my old branch... it says
pharshalp wants to merge 1 commit into matplotlib:master from **unknown repository**
) so closed the older PR and recreated it here.Sorry for the noise!
Please see #16428 the reviewers' comments, suggestions and discussion.
MaxNLocator
's docs were incorrect (please see the details described in #12729).Here is a numerical experiment that I ran to determine the difference between the number of tick locations returned by
MaxNLocator
and the argumentnbins
.It turns out (as was shown in the original issue) that
MaxNLocator
returns at mostnbins+2
tick locations (nbins+1
intervals).Since contour/contourf uses MaxNLocator (as pointed out in the original issue) updated their docs as well.
PR Checklist