@@ -86,8 +86,8 @@ def get_transform(self):
86
86
87
87
def _mask_non_positives (a ):
88
88
"""
89
- Return a Numpy masked array where all non-positive values are
90
- replaced with NaNs. If there are no non-positive values, the
89
+ Return a Numpy array where all non-positive values are
90
+ replaced with NaNs. If there are no non-positive values, the
91
91
original array is returned.
92
92
"""
93
93
mask = a <= 0.0
@@ -97,6 +97,7 @@ def _mask_non_positives(a):
97
97
98
98
99
99
def _clip_non_positives (a ):
100
+ a = np .array (a , float )
100
101
a [a <= 0.0 ] = 1e-300
101
102
return a
102
103
@@ -120,8 +121,6 @@ class Log10Transform(LogTransformBase):
120
121
121
122
def transform_non_affine (self , a ):
122
123
a = self ._handle_nonpos (a * 10.0 )
123
- if isinstance (a , ma .MaskedArray ):
124
- return ma .log10 (a )
125
124
return np .log10 (a )
126
125
127
126
def inverted (self ):
@@ -147,8 +146,6 @@ class Log2Transform(LogTransformBase):
147
146
148
147
def transform_non_affine (self , a ):
149
148
a = self ._handle_nonpos (a * 2.0 )
150
- if isinstance (a , ma .MaskedArray ):
151
- return ma .log (a ) / np .log (2 )
152
149
return np .log2 (a )
153
150
154
151
def inverted (self ):
@@ -174,8 +171,6 @@ class NaturalLogTransform(LogTransformBase):
174
171
175
172
def transform_non_affine (self , a ):
176
173
a = self ._handle_nonpos (a * np .e )
177
- if isinstance (a , ma .MaskedArray ):
178
- return ma .log (a )
179
174
return np .log (a )
180
175
181
176
def inverted (self ):
@@ -212,8 +207,6 @@ def __init__(self, base, nonpos):
212
207
213
208
def transform_non_affine (self , a ):
214
209
a = self ._handle_nonpos (a * self .base )
215
- if isinstance (a , ma .MaskedArray ):
216
- return ma .log (a ) / np .log (self .base )
217
210
return np .log (a ) / np .log (self .base )
218
211
219
212
def inverted (self ):
@@ -480,18 +473,18 @@ def get_transform(self):
480
473
481
474
def _mask_non_logit (a ):
482
475
"""
483
- Return a Numpy masked array where all values outside ]0, 1[ are
484
- masked . If all values are inside ]0, 1[, the original array is
485
- returned.
476
+ Return a Numpy array where all values outside ]0, 1[ are
477
+ replaced with NaNs . If all values are inside ]0, 1[, the original
478
+ array is returned.
486
479
"""
487
- a = a .copy ()
488
480
mask = (a <= 0.0 ) | (a >= 1.0 )
489
- a [mask ] = np .nan
481
+ if mask .any ():
482
+ return np .where (mask , np .nan , a )
490
483
return a
491
484
492
485
493
486
def _clip_non_logit (a ):
494
- a = a . copy ( )
487
+ a = np . array ( a , float )
495
488
a [a <= 0.0 ] = 1e-300
496
489
a [a >= 1.0 ] = 1 - 1e-300
497
490
return a
@@ -514,8 +507,6 @@ def __init__(self, nonpos):
514
507
def transform_non_affine (self , a ):
515
508
"""logit transform (base 10), masked or clipped"""
516
509
a = self ._handle_nonpos (a )
517
- if isinstance (a , ma .MaskedArray ):
518
- return ma .log10 (1.0 * a / (1.0 - a ))
519
510
return np .log10 (1.0 * a / (1.0 - a ))
520
511
521
512
def inverted (self ):
@@ -574,6 +565,9 @@ def set_default_locators_and_formatters(self, axis):
574
565
axis .set_minor_formatter (LogitFormatter ())
575
566
576
567
def limit_range_for_scale (self , vmin , vmax , minpos ):
568
+ """
569
+ Limit the domain to values between 0 and 1 (excluded).
570
+ """
577
571
return (vmin <= 0 and minpos or vmin ,
578
572
vmax >= 1 and (1 - minpos ) or vmax )
579
573
0 commit comments