@@ -292,8 +292,11 @@ class LogTransform(Transform):
292
292
293
293
def __init__ (self , base , nonpos = 'clip' ):
294
294
Transform .__init__ (self )
295
+ if base <= 0 or base == 1 :
296
+ raise ValueError ('The log base cannot be <= 0 or == 1' )
295
297
self .base = base
296
- self ._clip = {"clip" : True , "mask" : False }[nonpos ]
298
+ self ._clip = cbook ._check_getitem (
299
+ {"clip" : True , "mask" : False }, nonpos = nonpos )
297
300
298
301
def __str__ (self ):
299
302
return "{}(base={}, nonpos={!r})" .format (
@@ -368,41 +371,27 @@ def __init__(self, axis, **kwargs):
368
371
----------
369
372
axis : `~matplotlib.axis.Axis`
370
373
The axis for the scale.
371
- basex, basey : float, default: 10
374
+ base : float, default: 10
372
375
The base of the logarithm.
373
- nonposx, nonposy : {'clip', 'mask'}, default: 'clip'
376
+ nonpos : {'clip', 'mask'}, default: 'clip'
374
377
Determines the behavior for non-positive values. They can either
375
378
be masked as invalid, or clipped to a very small positive number.
376
- subsx, subsy : sequence of int, default: None
377
- Where to place the subticks between each major tick.
378
- For example, in a log10 scale: ``[2, 3, 4, 5, 6, 7, 8, 9]``
379
- will place 8 logarithmically spaced minor ticks between
380
- each major tick.
379
+ subs : sequence of int, default: None
380
+ Where to place the subticks between each major tick. For example,
381
+ in a log10 scale, ``[2, 3, 4, 5, 6, 7, 8, 9]`` will place 8
382
+ logarithmically spaced minor ticks between each major tick.
381
383
"""
382
- if axis .axis_name == 'x' :
383
- base = kwargs .pop ('basex' , 10.0 )
384
- subs = kwargs .pop ('subsx' , None )
385
- nonpos = kwargs .pop ('nonposx' , 'clip' )
386
- cbook ._check_in_list (['mask' , 'clip' ], nonposx = nonpos )
387
- else :
388
- base = kwargs .pop ('basey' , 10.0 )
389
- subs = kwargs .pop ('subsy' , None )
390
- nonpos = kwargs .pop ('nonposy' , 'clip' )
391
- cbook ._check_in_list (['mask' , 'clip' ], nonposy = nonpos )
392
-
393
- if kwargs :
394
- raise TypeError (f"LogScale got an unexpected keyword "
395
- f"argument { next (iter (kwargs ))!r} " )
396
-
397
- if base <= 0 or base == 1 :
398
- raise ValueError ('The log base cannot be <= 0 or == 1' )
384
+ @cbook ._rename_parameter ("3.2" , f"base{ axis .axis_name } " , "base" )
385
+ @cbook ._rename_parameter ("3.2" , f"subs{ axis .axis_name } " , "subs" )
386
+ @cbook ._rename_parameter ("3.2" , f"nonpos{ axis .axis_name } " , "nonpos" )
387
+ def __init__ (* , base = 10 , subs = None , nonpos = 'clip' ):
388
+ return base , subs , nonpos
399
389
390
+ base , subs , nonpos = __init__ (** kwargs )
400
391
self ._transform = LogTransform (base , nonpos )
401
392
self .subs = subs
402
393
403
- @property
404
- def base (self ):
405
- return self ._transform .base
394
+ base = property (lambda self : self ._transform .base )
406
395
407
396
def set_default_locators_and_formatters (self , axis ):
408
397
# docstring inherited
@@ -473,6 +462,12 @@ class SymmetricalLogTransform(Transform):
473
462
474
463
def __init__ (self , base , linthresh , linscale ):
475
464
Transform .__init__ (self )
465
+ if base <= 1.0 :
466
+ raise ValueError ("'base' must be larger than 1" )
467
+ if linthresh <= 0.0 :
468
+ raise ValueError ("'linthresh' must be positive" )
469
+ if linscale <= 0.0 :
470
+ raise ValueError ("'linscale' must be positive" )
476
471
self .base = base
477
472
self .linthresh = linthresh
478
473
self .linscale = linscale
@@ -536,19 +531,19 @@ class SymmetricalLogScale(ScaleBase):
536
531
537
532
Parameters
538
533
----------
539
- basex, basey : float
534
+ base : float
540
535
The base of the logarithm. Defaults to 10.
541
536
542
- linthreshx, linthreshy : float
537
+ linthresh : float
543
538
Defines the range ``(-x, x)``, within which the plot is linear.
544
539
This avoids having the plot go to infinity around zero. Defaults to 2.
545
540
546
- subsx, subsy : sequence of int
541
+ subs : sequence of int
547
542
Where to place the subticks between each major tick.
548
543
For example, in a log10 scale: ``[2, 3, 4, 5, 6, 7, 8, 9]`` will place
549
544
8 logarithmically spaced minor ticks between each major tick.
550
545
551
- linscalex, linscaley : float, optional
546
+ linscale : float, optional
552
547
This allows the linear range ``(-linthresh, linthresh)`` to be
553
548
stretched relative to the logarithmic range. Its value is the number of
554
549
decades to use for each half of the linear range. For example, when
@@ -562,40 +557,31 @@ class SymmetricalLogScale(ScaleBase):
562
557
InvertedSymmetricalLogTransform = InvertedSymmetricalLogTransform
563
558
564
559
def __init__ (self , axis , ** kwargs ):
565
- if axis .axis_name == 'x' :
566
- base = kwargs .pop ('basex' , 10.0 )
567
- linthresh = kwargs .pop ('linthreshx' , 2.0 )
568
- subs = kwargs .pop ('subsx' , None )
569
- linscale = kwargs .pop ('linscalex' , 1.0 )
570
- else :
571
- base = kwargs .pop ('basey' , 10.0 )
572
- linthresh = kwargs .pop ('linthreshy' , 2.0 )
573
- subs = kwargs .pop ('subsy' , None )
574
- linscale = kwargs .pop ('linscaley' , 1.0 )
575
- if kwargs :
576
- warn_deprecated (
577
- '3.2.0' ,
578
- message = (
579
- f"SymmetricalLogScale got an unexpected keyword "
580
- f"argument { next (iter (kwargs ))!r} . "
581
- 'In the future this will raise TypeError' )
582
- )
583
- # raise TypeError(f"SymmetricalLogScale got an unexpected keyword "
584
- # f"argument {next(iter(kwargs))!r}")
585
-
586
- if base <= 1.0 :
587
- raise ValueError ("'basex/basey' must be larger than 1" )
588
- if linthresh <= 0.0 :
589
- raise ValueError ("'linthreshx/linthreshy' must be positive" )
590
- if linscale <= 0.0 :
591
- raise ValueError ("'linscalex/linthreshy' must be positive" )
592
-
560
+ rename_parameter = cbook ._rename_parameter
561
+
562
+ @rename_parameter ("3.2" , f"base{ axis .axis_name } " , "base" )
563
+ @rename_parameter ("3.2" , f"linthresh{ axis .axis_name } " , "linthresh" )
564
+ @rename_parameter ("3.2" , f"subs{ axis .axis_name } " , "subs" )
565
+ @rename_parameter ("3.2" , f"linscale{ axis .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 )
593
578
self ._transform = SymmetricalLogTransform (base , linthresh , linscale )
594
- self .base = base
595
- self .linthresh = linthresh
596
- self .linscale = linscale
597
579
self .subs = subs
598
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
+
599
585
def set_default_locators_and_formatters (self , axis ):
600
586
# docstring inherited
601
587
axis .set_major_locator (SymmetricalLogLocator (self .get_transform ()))
0 commit comments