@@ -281,8 +281,11 @@ class LogTransform(Transform):
281
281
282
282
def __init__ (self , base , nonpos = 'clip' ):
283
283
Transform .__init__ (self )
284
+ if base <= 0 or base == 1 :
285
+ raise ValueError ('The log base cannot be <= 0 or == 1' )
284
286
self .base = base
285
- self ._clip = {"clip" : True , "mask" : False }[nonpos ]
287
+ self ._clip = cbook ._check_getitem (
288
+ {"clip" : True , "mask" : False }, nonpos = nonpos )
286
289
287
290
def __str__ (self ):
288
291
return "{}(base={}, nonpos={!r})" .format (
@@ -362,41 +365,32 @@ def __init__(self, axis, **kwargs):
362
365
----------
363
366
axis : `~matplotlib.axis.Axis`
364
367
The axis for the scale.
365
- basex, basey : float, default: 10
368
+ base : float, default: 10
366
369
The base of the logarithm.
367
- nonposx, nonposy : {'clip', 'mask'}, default: 'clip'
370
+ nonpos : {'clip', 'mask'}, default: 'clip'
368
371
Determines the behavior for non-positive values. They can either
369
372
be masked as invalid, or clipped to a very small positive number.
370
- subsx, subsy : sequence of int, default: None
371
- Where to place the subticks between each major tick.
372
- For example, in a log10 scale: ``[2, 3, 4, 5, 6, 7, 8, 9]``
373
- will place 8 logarithmically spaced minor ticks between
374
- each major tick.
373
+ subs : sequence of int, default: None
374
+ Where to place the subticks between each major tick. For example,
375
+ in a log10 scale, ``[2, 3, 4, 5, 6, 7, 8, 9]`` will place 8
376
+ logarithmically spaced minor ticks between each major tick.
375
377
"""
376
- if axis .axis_name == 'x' :
377
- base = kwargs .pop ('basex' , 10.0 )
378
- subs = kwargs .pop ('subsx' , None )
379
- nonpos = kwargs .pop ('nonposx' , 'clip' )
380
- cbook ._check_in_list (['mask' , 'clip' ], nonposx = nonpos )
381
- else :
382
- base = kwargs .pop ('basey' , 10.0 )
383
- subs = kwargs .pop ('subsy' , None )
384
- nonpos = kwargs .pop ('nonposy' , 'clip' )
385
- cbook ._check_in_list (['mask' , 'clip' ], nonposy = nonpos )
386
-
387
- if kwargs :
388
- raise TypeError (f"LogScale got an unexpected keyword "
389
- f"argument { next (iter (kwargs ))!r} " )
390
-
391
- if base <= 0 or base == 1 :
392
- raise ValueError ('The log base cannot be <= 0 or == 1' )
393
-
378
+ # After the deprecation, the whole (outer) __init__ can be replaced by
379
+ # def __init__(self, axis, *, base=10, subs=None, nonpos="clip"): ...
380
+ # The following is to emit the right warnings depending on the axis
381
+ # used, as the *old* kwarg names depended on the axis.
382
+ axis_name = getattr (axis , "axis_name" , "x" )
383
+ @cbook ._rename_parameter ("3.3" , f"base{ axis_name } " , "base" )
384
+ @cbook ._rename_parameter ("3.3" , f"subs{ axis_name } " , "subs" )
385
+ @cbook ._rename_parameter ("3.3" , f"nonpos{ axis_name } " , "nonpos" )
386
+ def __init__ (* , base = 10 , subs = None , nonpos = "clip" ):
387
+ return base , subs , nonpos
388
+
389
+ base , subs , nonpos = __init__ (** kwargs )
394
390
self ._transform = LogTransform (base , nonpos )
395
391
self .subs = subs
396
392
397
- @property
398
- def base (self ):
399
- return self ._transform .base
393
+ base = property (lambda self : self ._transform .base )
400
394
401
395
def set_default_locators_and_formatters (self , axis ):
402
396
# docstring inherited
@@ -463,6 +457,12 @@ class SymmetricalLogTransform(Transform):
463
457
464
458
def __init__ (self , base , linthresh , linscale ):
465
459
Transform .__init__ (self )
460
+ if base <= 1.0 :
461
+ raise ValueError ("'base' must be larger than 1" )
462
+ if linthresh <= 0.0 :
463
+ raise ValueError ("'linthresh' must be positive" )
464
+ if linscale <= 0.0 :
465
+ raise ValueError ("'linscale' must be positive" )
466
466
self .base = base
467
467
self .linthresh = linthresh
468
468
self .linscale = linscale
@@ -523,19 +523,19 @@ class SymmetricalLogScale(ScaleBase):
523
523
524
524
Parameters
525
525
----------
526
- basex, basey : float, default: 10
526
+ base : float, default: 10
527
527
The base of the logarithm.
528
528
529
- linthreshx, linthreshy : float, default: 2
529
+ linthresh : float, default: 2
530
530
Defines the range ``(-x, x)``, within which the plot is linear.
531
531
This avoids having the plot go to infinity around zero.
532
532
533
- subsx, subsy : sequence of int
533
+ subs : sequence of int
534
534
Where to place the subticks between each major tick.
535
535
For example, in a log10 scale: ``[2, 3, 4, 5, 6, 7, 8, 9]`` will place
536
536
8 logarithmically spaced minor ticks between each major tick.
537
537
538
- linscalex, linscaley : float, optional
538
+ linscale : float, optional
539
539
This allows the linear range ``(-linthresh, linthresh)`` to be
540
540
stretched relative to the logarithmic range. Its value is the number of
541
541
decades to use for each half of the linear range. For example, when
@@ -557,40 +557,31 @@ def InvertedSymmetricalLogTransform(self):
557
557
return InvertedSymmetricalLogTransform
558
558
559
559
def __init__ (self , axis , ** kwargs ):
560
- if axis .axis_name == 'x' :
561
- base = kwargs .pop ('basex' , 10.0 )
562
- linthresh = kwargs .pop ('linthreshx' , 2.0 )
563
- subs = kwargs .pop ('subsx' , None )
564
- linscale = kwargs .pop ('linscalex' , 1.0 )
565
- else :
566
- base = kwargs .pop ('basey' , 10.0 )
567
- linthresh = kwargs .pop ('linthreshy' , 2.0 )
568
- subs = kwargs .pop ('subsy' , None )
569
- linscale = kwargs .pop ('linscaley' , 1.0 )
570
- if kwargs :
571
- warn_deprecated (
572
- '3.2.0' ,
573
- message = (
574
- f"SymmetricalLogScale got an unexpected keyword "
575
- f"argument { next (iter (kwargs ))!r} . "
576
- 'In the future this will raise TypeError' )
577
- )
578
- # raise TypeError(f"SymmetricalLogScale got an unexpected keyword "
579
- # f"argument {next(iter(kwargs))!r}")
580
-
581
- if base <= 1.0 :
582
- raise ValueError ("'basex/basey' must be larger than 1" )
583
- if linthresh <= 0.0 :
584
- raise ValueError ("'linthreshx/linthreshy' must be positive" )
585
- if linscale <= 0.0 :
586
- raise ValueError ("'linscalex/linthreshy' must be positive" )
587
-
560
+ axis_name = getattr (axis , "axis_name" , "x" )
561
+ # See explanation in LogScale.__init__.
562
+ @cbook ._rename_parameter ("3.3" , f"base{ axis_name } " , "base" )
563
+ @cbook ._rename_parameter ("3.3" , f"linthresh{ axis_name } " , "linthresh" )
564
+ @cbook ._rename_parameter ("3.3" , f"subs{ axis_name } " , "subs" )
565
+ @cbook ._rename_parameter ("3.3" , f"linscale{ axis_name } " , "linscale" )
566
+ def __init__ (* , base = 10 , linthresh = 2 , subs = None , linscale = 1 , ** kwargs ):
567
+ if kwargs :
568
+ warn_deprecated (
569
+ "3.2.0" ,
570
+ message = (
571
+ f"SymmetricalLogScale got an unexpected keyword "
572
+ f"argument { next (iter (kwargs ))!r} ; in the future, "
573
+ f"this will raise a TypeError" )
574
+ )
575
+ return base , linthresh , subs , linscale
576
+
577
+ base , linthresh , subs , linscale = __init__ (** kwargs )
588
578
self ._transform = SymmetricalLogTransform (base , linthresh , linscale )
589
- self .base = base
590
- self .linthresh = linthresh
591
- self .linscale = linscale
592
579
self .subs = subs
593
580
581
+ base = property (lambda self : self ._transform .base )
582
+ linthresh = property (lambda self : self ._transform .linthresh )
583
+ linscale = property (lambda self : self ._transform .linscale )
584
+
594
585
def set_default_locators_and_formatters (self , axis ):
595
586
# docstring inherited
596
587
axis .set_major_locator (SymmetricalLogLocator (self .get_transform ()))
0 commit comments