@@ -1262,29 +1262,40 @@ def _make_norm_from_scale(scale_cls, base_norm_cls=None, *, init=None):
12621262 After ::
12631263
12641264 @_make_norm_from_scale(scale_cls)
1265- class base_norm_cls (Normalize):
1265+ class norm_cls (Normalize):
12661266 ...
12671267
1268- *base_norm_cls* is filled with methods so that normalization computations
1269- are forwarded to *scale_cls* (i.e., *scale_cls* is the scale that would be
1270- used for the colorbar of a mappable normalized with *base_norm_cls*).
1271-
1272- The constructor signature of *base_norm_cls* is derived from the
1273- constructor signature of *scale_cls*, but can be overridden using *init*
1274- (a callable which is *only* used for its signature).
1268+ *norm_cls* is filled with methods so that normalization computations are
1269+ forwarded to *scale_cls* (i.e., *scale_cls* is the scale that would be used
1270+ for the colorbar of a mappable normalized with *norm_cls*).
1271+
1272+ If *init* is not passed, then the constructor signature of *norm_cls*
1273+ will be ``norm_cls(vmin=None, vmax=None, clip=False)``; these three
1274+ parameters will be forwarded to the base class (``Normalize.__init__``),
1275+ and a *scale_cls* object will be initialized with no arguments (other than
1276+ a dummy axis).
1277+
1278+ If the *scale_cls* constructor takes additional parameters, then *init*
1279+ should be passed to `_make_norm_from_scale`. It is a callable which is
1280+ *only* used for its signature. First, this signature will become the
1281+ signature of *norm_cls*. Second, the *norm_cls* constructor will bind the
1282+ parameters passed to it using this signature, extract the bound *vmin*,
1283+ *vmax*, and *clip* values, pass those to ``Normalize.__init__``, and
1284+ forward the remaining bound values (including any defaults defined by the
1285+ signature) to the *scale_cls* constructor.
12751286 """
12761287
12771288 if base_norm_cls is None :
12781289 return functools .partial (_make_norm_from_scale , scale_cls , init = init )
12791290
12801291 if init is None :
12811292 def init (vmin = None , vmax = None , clip = False ): pass
1282- init_signature = inspect .signature (init )
1293+ bound_init_signature = inspect .signature (init )
12831294
12841295 class Norm (base_norm_cls ):
12851296
12861297 def __init__ (self , * args , ** kwargs ):
1287- ba = init_signature .bind (* args , ** kwargs )
1298+ ba = bound_init_signature .bind (* args , ** kwargs )
12881299 ba .apply_defaults ()
12891300 super ().__init__ (
12901301 ** {k : ba .arguments .pop (k ) for k in ["vmin" , "vmax" , "clip" ]})
@@ -1329,6 +1340,9 @@ def inverse(self, value):
13291340 Norm .__name__ = base_norm_cls .__name__
13301341 Norm .__qualname__ = base_norm_cls .__qualname__
13311342 Norm .__module__ = base_norm_cls .__module__
1343+ Norm .__init__ .__signature__ = bound_init_signature .replace (parameters = [
1344+ inspect .Parameter ("self" , inspect .Parameter .POSITIONAL_OR_KEYWORD ),
1345+ * bound_init_signature .parameters .values ()])
13321346 return Norm
13331347
13341348
0 commit comments