@@ -964,36 +964,38 @@ def changed(self):
964964 label .set_color (self .labelMappable .to_rgba (cv ))
965965 super ().changed ()
966966
967- def _autolev (self , N ):
967+ def _set_locator_if_none (self , N ):
968968 """
969- Select contour levels to span the data .
969+ Set a locator on this ContourSet if it's not already set .
970970
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.
981975
982976 Parameters
983977 ----------
984- N : int | None
978+ N : int or None
985979 """
986980 if self .locator is None :
987981 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 )
992983 else :
993984 if N is None :
994985 N = 7 # Hard coded default
995986 self .locator = ticker .MaxNLocator (N + 1 , min_n_ticks = 1 )
996987
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+ """
997999 lev = self .locator .tick_values (self .zmin , self .zmax )
9981000
9991001 try :
@@ -1028,13 +1030,11 @@ def _process_contour_level_args(self, args, z_dtype):
10281030 levels_arg = args [0 ]
10291031 elif np .issubdtype (z_dtype , bool ):
10301032 # 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 ]
10351034
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 ()
10381038 else :
10391039 self .levels = np .asarray (levels_arg , np .float64 )
10401040
0 commit comments