-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Doc: Clarify default levels behavior in contour/contourf #31016
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
Conversation
Explicitly state that the default levels corresponds to n=7 and clarifies that int input targets n+1 levels but may produce n+2.
3c6bd7d to
adbf65f
Compare
adbf65f to
e64f5eb
Compare
|
@timhoffm can you please take a look on this as well |
|
I prefer the wording in #31013 and it has precedence since it was opened first. I just haven't had a chance to check if the build errors are real. |
|
@story645 since #31013 is not mentioned his pr on issue I worked on it for hours I updated the code so it directly addresses @lucyleeow's question about needing the exact number while maintaining the "reasonable" language @timhoffm suggested. If an int *n*, use `~matplotlib.ticker.MaxNLocator`, which tries
to automatically choose no more than *n+1* "nice" contour levels
|
|
@story645 Thoughts on my reply ?? |
Please keep in mind that our project favors collaboration (contributing guide) and that the solution in #31013 was proposed before @lucyleeow's comment. I won't have the bandwith to verify Lucy's correction for the next few days but it would be quite valuable if you'd do so by pulling up the code that does the computation, walking through it, and succinctly writing it up. Please also be thoughtful in your AI use - I'm not just feeding these instructions into a chat b/c the human verification is the important part. |
lib/matplotlib/contour.py
Outdated
| If an int *n*, use `~matplotlib.ticker.MaxNLocator`, which tries to | ||
| automatically choose no more than *n+2* "nice" contour levels | ||
| between the minimum and maximum numeric values of *Z*. |
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 is still not correct, it uses MaxNLocator to choose no more that n+2 "boundaries". But that has to be translated to number of contour lines / regions. I think - but to be checked - for contour the number of lines is the number of boundaries, but for contourfthe number of filled regions is one more.
@sanrishi if you want, you are welcome to verify this and reopen with an update on this part of the docs.
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.
@timhoffm I have updated the docstring to use the "boundaries" definition and added the verification plots
Ready for review!
The previous documentation stated that `MaxNLocator` chooses "no more than n+1" levels, which was mathematically incorrect for the default case (n=7 produces 9 levels). Additionally, the distinction between `contour` (lines) and `contourf` (filled regions) created confusion, as `contourf` produces one fewer region than the number of lines (unless `extend` is used). This update redefines `levels` strictly as "contour boundaries." This terminology: 1. Is accurate for both functions (lines are at boundaries, regions are between them). 2. Remains correct regardless of the `extend` parameter. 3. Explicitly documents the default behavior for n=7.
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
|
@timhoffm timeout is still happening |
|
Yes, I know. Timeouts are much rarer now, but still occur. |
|
@timhoffm should we proceed to solve remaining timeout issue or this is acceptable? |
|
Of course, fixing the timeouts remains highly desirable. |
PR summary
Problem
The documentation for the
levelsparameter was ambiguous regarding the exact number of resulting lines versus filled regions. It stated "no more than n+1" levels, butMaxNLocatoroften producesn+2boundaries (e.g., inputn=7results in 9 boundaries).Solution
I have updated the docstring to define
levelsspecifically as "contour boundaries". This resolves the ambiguity because:contour()draws lines at these boundaries.contourf()fills the regions between these boundaries.This definition remains accurate even when
extendis used (which adds extra regions beyond the boundaries) or whenMaxNLocatoradjusts the tick count.Verification
I verified the behavior locally using a test script to compare
MaxNLocatoroutput against the actual generated lines and collections.Findings for
levels=n:MaxNLocatorproduces up ton+2boundaries.contourproducesn+2lines.contourfproducesn+1filled regions (inherentlyN_boundaries - 1).Visual Proof:
I generated the following comparison to demonstrate that filled regions exist between the lines, confirming that the "Boundaries" terminology is the correct source of truth.
contourandcontourflevels default not specified #30996" is in the body of the PR description to link the related issue