Skip to content

[Doc]: contour and contourf levels default not specified #30996

@lucyleeow

Description

@lucyleeow

Documentation Link

https://matplotlib.org/devdocs/api/_as_gen/matplotlib.pyplot.contourf.html

Problem

levels is specified to be optional but the default value is not specified.

Suggested improvement

Digging into the code, it seems that _process_contour_level_args is responsible? It calls _ensure_locator_exists :

def _ensure_locator_exists(self, N):
"""
Set a locator on this ContourSet if it's not already set.
Parameters
----------
N : int or None
If *N* is an int, it is used as the target number of levels.
Otherwise when *N* is None, a reasonable default is chosen;
for logscales the LogLocator chooses, N=7 is the default
otherwise.
"""
if self.locator is None:
if self.logscale:
self.locator = ticker.LogLocator(numticks=N)
else:
if N is None:
N = 7 # Hard coded default
self.locator = ticker.MaxNLocator(N + 1, min_n_ticks=1)

So does this mean that levels=1 gets passed as MaxNLocator(n_bins=2) which gives max n_bins + 1 (3) levels?

Also in levels it is specified:

If an int n, use MaxNLocator, which tries to automatically choose no more than n+1 "nice" contour levels between minimum and maximum numeric values of Z.

But considering we pass MaxNLocator(N+1), is it n+1 or n+2 ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions