@@ -964,36 +964,38 @@ def changed(self):
964
964
label .set_color (self .labelMappable .to_rgba (cv ))
965
965
super ().changed ()
966
966
967
- def _autolev (self , N ):
967
+ def _set_locator_if_none (self , N ):
968
968
"""
969
- Select contour levels to span the data .
969
+ Set a locator on this ContourSet if it's not already set .
970
970
971
- The target number of levels, *N*, is used only when the
972
- locator is not set and the scale is log or the default
973
- locator is used.
974
-
975
- We need two more levels for filled contours than for
976
- line contours, because for the latter we need to specify
977
- the lower and upper boundary of each range. For example,
978
- a single contour boundary, say at z = 0, requires only
979
- one contour line, but two filled regions, and therefore
980
- three levels to provide boundaries for both regions.
971
+ If *N* is an int, it is used as the target number of levels.
972
+ Otherwise when *N* is None, a reasonable default is chosen;
973
+ for logscales the LogLocator chooses, N=7 is the default
974
+ otherwise.
981
975
982
976
Parameters
983
977
----------
984
- N : int | None
978
+ N : int or None
985
979
"""
986
980
if self .locator is None :
987
981
if self .logscale :
988
- if N is None :
989
- self .locator = ticker .LogLocator ()
990
- else :
991
- self .locator = ticker .LogLocator (numticks = N )
982
+ self .locator = ticker .LogLocator (numticks = N )
992
983
else :
993
984
if N is None :
994
985
N = 7 # Hard coded default
995
986
self .locator = ticker .MaxNLocator (N + 1 , min_n_ticks = 1 )
996
987
988
+ def _autolev (self ):
989
+ """
990
+ Select contour levels to span the data.
991
+
992
+ We need two more levels for filled contours than for
993
+ line contours, because for the latter we need to specify
994
+ the lower and upper boundary of each range. For example,
995
+ a single contour boundary, say at z = 0, requires only
996
+ one contour line, but two filled regions, and therefore
997
+ three levels to provide boundaries for both regions.
998
+ """
997
999
lev = self .locator .tick_values (self .zmin , self .zmax )
998
1000
999
1001
try :
@@ -1028,13 +1030,11 @@ def _process_contour_level_args(self, args, z_dtype):
1028
1030
levels_arg = args [0 ]
1029
1031
elif np .issubdtype (z_dtype , bool ):
1030
1032
# Set default values for bool data types
1031
- if self .filled :
1032
- levels_arg = [0 , .5 , 1 ]
1033
- else :
1034
- levels_arg = [.5 ]
1033
+ levels_arg = [0 , .5 , 1 ] if self .filled else [.5 ]
1035
1034
1036
- if isinstance (levels_arg , (Integral , None )):
1037
- self .levels = self ._autolev (levels_arg )
1035
+ if isinstance (levels_arg , Integral ) or levels_arg is None :
1036
+ self ._set_locator_if_none (levels_arg )
1037
+ self .levels = self ._autolev ()
1038
1038
else :
1039
1039
self .levels = np .asarray (levels_arg , np .float64 )
1040
1040
0 commit comments