@@ -77,10 +77,18 @@ def __init__(self, axis):
7777 For back-compatibility reasons, scales take an `~matplotlib.axis.Axis`
7878 object as the first argument.
7979
80- The current recommendation for `.ScaleBase` subclasses is to have the
81- *axis* parameter for API compatibility, but not make use of it. This is
82- because we plan to remove this argument to make a scale object usable
83- by multiple `~matplotlib.axis.Axis`\es at the same time.
80+ .. deprecated:: 3.11
81+
82+ The *axis* parameter is now optional, i.e. matplotlib is compatible
83+ with `.ScaleBase` subclasses that do not take an *axis* parameter.
84+
85+ The *axis* parameter is pending-deprecated. It will be deprecated
86+ in matplotlib 3.13, and removed in matplotlib 3.15.
87+
88+ 3rd-party scales are recommended to remove the *axis* parameter now
89+ if they can afford to restrict compatibility to matplotlib >= 3.11
90+ already. Otherwise, they may keep the *axis* parameter and remove it
91+ in time for matplotlib 3.13.
8492 """
8593
8694 def get_transform (self ):
@@ -801,6 +809,20 @@ def limit_range_for_scale(self, vmin, vmax, minpos):
801809 'functionlog' : FuncScaleLog ,
802810 }
803811
812+ # caching of signature info
813+ # For backward compatibility, the built-in scales will keep the *axis* parameter
814+ # in their constructors until matplotlib 3.15, i.e. as long as the *axis* parameter
815+ # is still supported.
816+ _scale_has_axis_parameter = {
817+ 'linear' : True ,
818+ 'log' : True ,
819+ 'symlog' : True ,
820+ 'asinh' : True ,
821+ 'logit' : True ,
822+ 'function' : True ,
823+ 'functionlog' : True ,
824+ }
825+
804826
805827def get_scale_names ():
806828 """Return the names of the available scales."""
@@ -817,7 +839,11 @@ def scale_factory(scale, axis, **kwargs):
817839 axis : `~matplotlib.axis.Axis`
818840 """
819841 scale_cls = _api .check_getitem (_scale_mapping , scale = scale )
820- return scale_cls (axis , ** kwargs )
842+
843+ if _scale_has_axis_parameter [scale ]:
844+ return scale_cls (axis , ** kwargs )
845+ else :
846+ return scale_cls (** kwargs )
821847
822848
823849if scale_factory .__doc__ :
@@ -836,6 +862,20 @@ def register_scale(scale_class):
836862 """
837863 _scale_mapping [scale_class .name ] = scale_class
838864
865+ # migration code to handle the *axis* parameter
866+ has_axis_parameter = "axis" in inspect .signature (scale_class ).parameters
867+ _scale_has_axis_parameter [scale_class .name ] = has_axis_parameter
868+ if has_axis_parameter :
869+ _api .warn_deprecated (
870+ "3.11" ,
871+ message = f"The scale { scale_class .__qualname__ !r} uses an 'axis' parameter "
872+ "in the constructors. This parameter is pending-deprecated since "
873+ "matplotlib 3.11. It will be fully deprecated in 3.13 and removed "
874+ "in 3.15. Starting with 3.11, 'register_scale()' accepts scales "
875+ "without the *axis* parameter." ,
876+ pending = True ,
877+ )
878+
839879
840880def _get_scale_docs ():
841881 """
0 commit comments