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 ?
Documentation Link
https://matplotlib.org/devdocs/api/_as_gen/matplotlib.pyplot.contourf.html
Problem
levelsis specified to be optional but the default value is not specified.Suggested improvement
Digging into the code, it seems that
_process_contour_level_argsis responsible? It calls_ensure_locator_exists:matplotlib/lib/matplotlib/contour.py
Lines 957 to 975 in ebf9b14
So does this mean that
levels=1gets passed asMaxNLocator(n_bins=2)which gives maxn_bins + 1(3) levels?Also in
levelsit is specified:But considering we pass
MaxNLocator(N+1), is it n+1 or n+2 ?