Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c640f77

Browse files
author
Fabio Zanini
committed
Various fixes suggested by Eric
1 parent 76840ea commit c640f77

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

lib/matplotlib/scale.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ def get_transform(self):
8686

8787
def _mask_non_positives(a):
8888
"""
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
9191
original array is returned.
9292
"""
9393
mask = a <= 0.0
@@ -97,6 +97,7 @@ def _mask_non_positives(a):
9797

9898

9999
def _clip_non_positives(a):
100+
a = np.array(a, float)
100101
a[a <= 0.0] = 1e-300
101102
return a
102103

@@ -120,8 +121,6 @@ class Log10Transform(LogTransformBase):
120121

121122
def transform_non_affine(self, a):
122123
a = self._handle_nonpos(a * 10.0)
123-
if isinstance(a, ma.MaskedArray):
124-
return ma.log10(a)
125124
return np.log10(a)
126125

127126
def inverted(self):
@@ -147,8 +146,6 @@ class Log2Transform(LogTransformBase):
147146

148147
def transform_non_affine(self, a):
149148
a = self._handle_nonpos(a * 2.0)
150-
if isinstance(a, ma.MaskedArray):
151-
return ma.log(a) / np.log(2)
152149
return np.log2(a)
153150

154151
def inverted(self):
@@ -174,8 +171,6 @@ class NaturalLogTransform(LogTransformBase):
174171

175172
def transform_non_affine(self, a):
176173
a = self._handle_nonpos(a * np.e)
177-
if isinstance(a, ma.MaskedArray):
178-
return ma.log(a)
179174
return np.log(a)
180175

181176
def inverted(self):
@@ -212,8 +207,6 @@ def __init__(self, base, nonpos):
212207

213208
def transform_non_affine(self, a):
214209
a = self._handle_nonpos(a * self.base)
215-
if isinstance(a, ma.MaskedArray):
216-
return ma.log(a) / np.log(self.base)
217210
return np.log(a) / np.log(self.base)
218211

219212
def inverted(self):
@@ -480,18 +473,18 @@ def get_transform(self):
480473

481474
def _mask_non_logit(a):
482475
"""
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.
486479
"""
487-
a = a.copy()
488480
mask = (a <= 0.0) | (a >= 1.0)
489-
a[mask] = np.nan
481+
if mask.any():
482+
return np.where(mask, np.nan, a)
490483
return a
491484

492485

493486
def _clip_non_logit(a):
494-
a = a.copy()
487+
a = np.array(a, float)
495488
a[a <= 0.0] = 1e-300
496489
a[a >= 1.0] = 1 - 1e-300
497490
return a
@@ -514,8 +507,6 @@ def __init__(self, nonpos):
514507
def transform_non_affine(self, a):
515508
"""logit transform (base 10), masked or clipped"""
516509
a = self._handle_nonpos(a)
517-
if isinstance(a, ma.MaskedArray):
518-
return ma.log10(1.0 * a / (1.0 - a))
519510
return np.log10(1.0 * a / (1.0 - a))
520511

521512
def inverted(self):
@@ -574,6 +565,9 @@ def set_default_locators_and_formatters(self, axis):
574565
axis.set_minor_formatter(LogitFormatter())
575566

576567
def limit_range_for_scale(self, vmin, vmax, minpos):
568+
"""
569+
Limit the domain to values between 0 and 1 (excluded).
570+
"""
577571
return (vmin <= 0 and minpos or vmin,
578572
vmax >= 1 and (1 - minpos) or vmax)
579573

lib/matplotlib/tests/test_scale.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_log_scales():
1919
def test_logit_scales():
2020
ax = plt.subplot(111, xscale='logit')
2121

22-
# Typical exctinction curve for logit
22+
# Typical extinction curve for logit
2323
x = np.array([0.001, 0.003, 0.01, 0.03, 0.1, 0.2, 0.3, 0.4, 0.5,
2424
0.6, 0.7, 0.8, 0.9, 0.97, 0.99, 0.997, 0.999])
2525
y = 1.0 / x

lib/matplotlib/ticker.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -812,14 +812,17 @@ class LogitFormatter(Formatter):
812812
def __call__(self, x, pos=None):
813813
s = ''
814814
if 0.01 <= x <= 0.99:
815-
if x in [.01, 0.1, 0.5, 0.9, 0.99]:
816-
s = '{:.2f}'.format(x)
815+
s = '{:.2f}'.format(x)
817816
elif x < 0.01:
818817
if is_decade(x):
819-
s = '$10^{%.0f}$' % np.log10(x)
820-
elif x > 0.99:
818+
s = '$10^{{{:.0f}}}$'.format(np.log10(x))
819+
else:
820+
s = '${:.5f}$'.format(x)
821+
else: # x > 0.99
821822
if is_decade(1-x):
822-
s = '$1-10^{%.0f}$' % np.log10(1-x)
823+
s = '$1-10^{{{:.0f}}}$'.format(np.log10(1-x))
824+
else:
825+
s = '$1-{:.5f}$'.format(1-x)
823826
return s
824827

825828
def format_data_short(self, value):

0 commit comments

Comments
 (0)