Skip to content

Commit 1cd6255

Browse files
authored
DOC: Clarify contour levels parameter as boundaries to fix ambiguity
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.
1 parent 787c773 commit 1cd6255

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

lib/matplotlib/contour.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,15 +1487,17 @@ def _initialize_x_y(self, z):
14871487
Determines the number and positions of the contour lines / regions.
14881488
14891489
If an int *n*, use `~matplotlib.ticker.MaxNLocator`, which tries to
1490-
automatically choose no more than *n+2* "nice" contour levels
1491-
between the minimum and maximum numeric values of *Z*.
1490+
automatically choose no more than *n+2* "nice" contour level boundaries
1491+
between the minimum and maximum numeric values of *Z*. These boundaries
1492+
define where lines are drawn (for `contour`) or where filled regions
1493+
are separated (for `contourf`).
14921494
14931495
If array-like, draw contour lines at the specified levels.
14941496
The values must be in increasing order.
14951497
1496-
If not given, a reasonable default is automatically chosen. For linear
1497-
scales, `~matplotlib.ticker.MaxNLocator` is used with *nbins*=8,
1498-
producing up to 9 "nice" contour levels. For logarithmic scales,
1498+
If not specified, a reasonable default is automatically chosen. For
1499+
linear scales, this corresponds to *n=7* (using `~.ticker.MaxNLocator(8)`),
1500+
producing up to 9 "nice" contour boundaries. For logarithmic scales,
14991501
`~matplotlib.ticker.LogLocator` is used instead.
15001502
15011503
Returns

0 commit comments

Comments
 (0)