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

Skip to content

Commit ea57339

Browse files
committed
Also rename nonpos->nonpositive.
1 parent a00c27c commit ea57339

File tree

6 files changed

+64
-61
lines changed

6 files changed

+64
-61
lines changed

doc/api/next_api_changes/deprecations.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,13 @@ log/symlog scale base, ticks, and nonpos specification
189189
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
190190
`~.Axes.semilogx`, `~.Axes.semilogy`, `~.Axes.loglog`, `.LogScale`, and
191191
`.SymmetricalLogScale` used to take keyword arguments that depends on the axis
192-
orientation ("basex" vs "basey", "nonposx" vs "nonposy"); these parameter names
193-
are now deprecated in favor of "base", "nonpos", etc. This deprecation also
194-
affects e.g. ``ax.set_yscale("log", basey=...)`` which must now be spelled
195-
``ax.set_yscale("log", base=...)``.
192+
orientation ("basex" vs "basey", "subsx" vs "subsy", "nonposx" vs "nonposy");
193+
these parameter names are now deprecated in favor of "base", "subs",
194+
"nonpositive". This deprecation also affects e.g. ``ax.set_yscale("log",
195+
basey=...)`` which must now be spelled ``ax.set_yscale("log", base=...)``.
196+
197+
The change from "nonpos" to "nonpositive" also affects `~.scale.LogTransform`,
198+
`~.scale.InvertedLogTransform`, `~.scale.SymmetricalLogTransform`, etc.
196199

197200
To use *different* bases for the x-axis and y-axis of a `~.Axes.loglog` plot,
198201
use e.g. ``ax.set_xscale("log", base=10); ax.set_yscale("log", base=2)``.

examples/scales/log_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
x = 10.0**np.linspace(0.0, 2.0, 20)
3737
y = x**2.0
3838

39-
ax4.set_xscale("log", nonpos='clip')
40-
ax4.set_yscale("log", nonpos='clip')
39+
ax4.set_xscale("log", nonpositive='clip')
40+
ax4.set_yscale("log", nonpositive='clip')
4141
ax4.set(title='Errorbars go negative')
4242
ax4.errorbar(x, y, xerr=0.1 * x, yerr=5.0 + 0.75 * y)
4343
# ylim must be set after errorbar to allow errorbar to autoscale limits

lib/matplotlib/axes/_axes.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,7 @@ def loglog(self, *args, **kwargs):
17661766
both the x-axis and the y-axis to log scaling. All of the concepts and
17671767
parameters of plot can be used here as well.
17681768
1769-
The additional parameters *base*, *subs* and *nonpos* control the
1769+
The additional parameters *base*, *subs* and *nonpositive* control the
17701770
x/y-axis properties. They are just forwarded to `.Axes.set_xscale` and
17711771
`.Axes.set_yscale`. To use different properties on the x-axis and the
17721772
y-axis, use e.g.
@@ -1782,7 +1782,7 @@ def loglog(self, *args, **kwargs):
17821782
are automatically chosen depending on the number of decades in the
17831783
plot. See `.Axes.set_xscale`/`.Axes.set_yscale` for details.
17841784
1785-
nonpos : {'mask', 'clip'}, default: 'mask'
1785+
nonpositive : {'mask', 'clip'}, default: 'mask'
17861786
Non-positive values can be masked as invalid, or clipped to a very
17871787
small positive number.
17881788
@@ -1797,10 +1797,12 @@ def loglog(self, *args, **kwargs):
17971797
All parameters supported by `.plot`.
17981798
"""
17991799
dx = {k: v for k, v in kwargs.items()
1800-
if k in ['base', 'subs', 'nonpos', 'basex', 'subsx', 'nonposx']}
1800+
if k in ['base', 'subs', 'nonpositive',
1801+
'basex', 'subsx', 'nonposx']}
18011802
self.set_xscale('log', **dx)
18021803
dy = {k: v for k, v in kwargs.items()
1803-
if k in ['base', 'subs', 'nonpos', 'basey', 'subsy', 'nonposy']}
1804+
if k in ['base', 'subs', 'nonpositive',
1805+
'basey', 'subsy', 'nonposy']}
18041806
self.set_yscale('log', **dy)
18051807
return self.plot(
18061808
*args, **{k: v for k, v in kwargs.items() if k not in {*dx, *dy}})
@@ -1820,7 +1822,7 @@ def semilogx(self, *args, **kwargs):
18201822
the x-axis to log scaling. All of the concepts and parameters of plot
18211823
can be used here as well.
18221824
1823-
The additional parameters *base*, *subs*, and *nonpos* control the
1825+
The additional parameters *base*, *subs*, and *nonpositive* control the
18241826
x-axis properties. They are just forwarded to `.Axes.set_xscale`.
18251827
18261828
Parameters
@@ -1833,7 +1835,7 @@ def semilogx(self, *args, **kwargs):
18331835
are automatically chosen depending on the number of decades in the
18341836
plot. See `.Axes.set_xscale` for details.
18351837
1836-
nonpos : {'mask', 'clip'}, default: 'mask'
1838+
nonpositive : {'mask', 'clip'}, default: 'mask'
18371839
Non-positive values in x can be masked as invalid, or clipped to a
18381840
very small positive number.
18391841
@@ -1848,7 +1850,8 @@ def semilogx(self, *args, **kwargs):
18481850
All parameters supported by `.plot`.
18491851
"""
18501852
d = {k: v for k, v in kwargs.items()
1851-
if k in ['base', 'subs', 'nonpos', 'basex', 'subsx', 'nonposx']}
1853+
if k in ['base', 'subs', 'nonpositive',
1854+
'basex', 'subsx', 'nonposx']}
18521855
self.set_xscale('log', **d)
18531856
return self.plot(
18541857
*args, **{k: v for k, v in kwargs.items() if k not in d})
@@ -1868,7 +1871,7 @@ def semilogy(self, *args, **kwargs):
18681871
the y-axis to log scaling. All of the concepts and parameters of plot
18691872
can be used here as well.
18701873
1871-
The additional parameters *base*, *subs*, and *nonpos* control the
1874+
The additional parameters *base*, *subs*, and *nonpositive* control the
18721875
y-axis properties. They are just forwarded to `.Axes.set_yscale`.
18731876
18741877
Parameters
@@ -1881,7 +1884,7 @@ def semilogy(self, *args, **kwargs):
18811884
are automatically chosen depending on the number of decades in the
18821885
plot. See `.Axes.set_yscale` for details.
18831886
1884-
nonpos : {'mask', 'clip'}, default: 'mask'
1887+
nonpositive : {'mask', 'clip'}, default: 'mask'
18851888
Non-positive values in y can be masked as invalid, or clipped to a
18861889
very small positive number.
18871890
@@ -1896,7 +1899,8 @@ def semilogy(self, *args, **kwargs):
18961899
All parameters supported by `.plot`.
18971900
"""
18981901
d = {k: v for k, v in kwargs.items()
1899-
if k in ['base', 'subs', 'nonpos', 'basey', 'subsy', 'nonposy']}
1902+
if k in ['base', 'subs', 'nonpositive',
1903+
'basey', 'subsy', 'nonposy']}
19001904
self.set_yscale('log', **d)
19011905
return self.plot(
19021906
*args, **{k: v for k, v in kwargs.items() if k not in d})
@@ -2340,11 +2344,11 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
23402344
if orientation == 'vertical':
23412345
self._process_unit_info(xdata=x, ydata=height, kwargs=kwargs)
23422346
if log:
2343-
self.set_yscale('log', nonpos='clip')
2347+
self.set_yscale('log', nonpositive='clip')
23442348
elif orientation == 'horizontal':
23452349
self._process_unit_info(xdata=width, ydata=y, kwargs=kwargs)
23462350
if log:
2347-
self.set_xscale('log', nonpos='clip')
2351+
self.set_xscale('log', nonpositive='clip')
23482352

23492353
# lets do some conversions now since some types cannot be
23502354
# subtracted uniformly
@@ -6712,9 +6716,9 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
67126716

67136717
if log:
67146718
if orientation == 'horizontal':
6715-
self.set_xscale('log', nonpos='clip')
6719+
self.set_xscale('log', nonpositive='clip')
67166720
else: # orientation == 'vertical'
6717-
self.set_yscale('log', nonpos='clip')
6721+
self.set_yscale('log', nonpositive='clip')
67186722

67196723
if align == 'left':
67206724
x -= 0.5*(bins[1]-bins[0])

lib/matplotlib/scale.py

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,17 @@ def inverted(self):
279279
class LogTransform(Transform):
280280
input_dims = output_dims = 1
281281

282-
def __init__(self, base, nonpos='clip'):
282+
@cbook._rename_parameter("3.3", "nonpos", "nonpositive")
283+
def __init__(self, base, nonpositive='clip'):
283284
Transform.__init__(self)
284285
if base <= 0 or base == 1:
285286
raise ValueError('The log base cannot be <= 0 or == 1')
286287
self.base = base
287288
self._clip = cbook._check_getitem(
288-
{"clip": True, "mask": False}, nonpos=nonpos)
289+
{"clip": True, "mask": False}, nonpositive=nonpositive)
289290

290291
def __str__(self):
291-
return "{}(base={}, nonpos={!r})".format(
292+
return "{}(base={}, nonpositive={!r})".format(
292293
type(self).__name__, self.base, "clip" if self._clip else "mask")
293294

294295
def transform_non_affine(self, a):
@@ -367,7 +368,7 @@ def __init__(self, axis, **kwargs):
367368
The axis for the scale.
368369
base : float, default: 10
369370
The base of the logarithm.
370-
nonpos : {'clip', 'mask'}, default: 'clip'
371+
nonpositive : {'clip', 'mask'}, default: 'clip'
371372
Determines the behavior for non-positive values. They can either
372373
be masked as invalid, or clipped to a very small positive number.
373374
subs : sequence of int, default: None
@@ -376,18 +377,18 @@ def __init__(self, axis, **kwargs):
376377
logarithmically spaced minor ticks between each major tick.
377378
"""
378379
# After the deprecation, the whole (outer) __init__ can be replaced by
379-
# def __init__(self, axis, *, base=10, subs=None, nonpos="clip"): ...
380+
# def __init__(self, axis, *, base=10, subs=None, nonpositive="clip")
380381
# The following is to emit the right warnings depending on the axis
381382
# used, as the *old* kwarg names depended on the axis.
382383
axis_name = getattr(axis, "axis_name", "x")
383384
@cbook._rename_parameter("3.3", f"base{axis_name}", "base")
384385
@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
386+
@cbook._rename_parameter("3.3", f"nonpos{axis_name}", "nonpositive")
387+
def __init__(*, base=10, subs=None, nonpositive="clip"):
388+
return base, subs, nonpositive
388389

389-
base, subs, nonpos = __init__(**kwargs)
390-
self._transform = LogTransform(base, nonpos)
390+
base, subs, nonpositive = __init__(**kwargs)
391+
self._transform = LogTransform(base, nonpositive)
391392
self.subs = subs
392393

393394
base = property(lambda self: self._transform.base)
@@ -598,11 +599,12 @@ def get_transform(self):
598599
class LogitTransform(Transform):
599600
input_dims = output_dims = 1
600601

601-
def __init__(self, nonpos='mask'):
602+
@cbook._rename_parameter("3.3", "nonpos", "nonpositive")
603+
def __init__(self, nonpositive='mask'):
602604
Transform.__init__(self)
603-
cbook._check_in_list(['mask', 'clip'], nonpos=nonpos)
604-
self._nonpos = nonpos
605-
self._clip = {"clip": True, "mask": False}[nonpos]
605+
cbook._check_in_list(['mask', 'clip'], nonpositive=nonpositive)
606+
self._nonpositive = nonpositive
607+
self._clip = {"clip": True, "mask": False}[nonpositive]
606608

607609
def transform_non_affine(self, a):
608610
"""logit transform (base 10), masked or clipped"""
@@ -614,28 +616,29 @@ def transform_non_affine(self, a):
614616
return out
615617

616618
def inverted(self):
617-
return LogisticTransform(self._nonpos)
619+
return LogisticTransform(self._nonpositive)
618620

619621
def __str__(self):
620-
return "{}({!r})".format(type(self).__name__, self._nonpos)
622+
return "{}({!r})".format(type(self).__name__, self._nonpositive)
621623

622624

623625
class LogisticTransform(Transform):
624626
input_dims = output_dims = 1
625627

626-
def __init__(self, nonpos='mask'):
628+
@cbook._rename_parameter("3.3", "nonpos", "nonpositive")
629+
def __init__(self, nonpositive='mask'):
627630
Transform.__init__(self)
628-
self._nonpos = nonpos
631+
self._nonpositive = nonpositive
629632

630633
def transform_non_affine(self, a):
631634
"""logistic transform (base 10)"""
632635
return 1.0 / (1 + 10**(-a))
633636

634637
def inverted(self):
635-
return LogitTransform(self._nonpos)
638+
return LogitTransform(self._nonpositive)
636639

637640
def __str__(self):
638-
return "{}({!r})".format(type(self).__name__, self._nonpos)
641+
return "{}({!r})".format(type(self).__name__, self._nonpositive)
639642

640643

641644
class LogitScale(ScaleBase):
@@ -647,20 +650,15 @@ class LogitScale(ScaleBase):
647650
"""
648651
name = 'logit'
649652

650-
def __init__(
651-
self,
652-
axis,
653-
nonpos='mask',
654-
*,
655-
one_half=r"\frac{1}{2}",
656-
use_overline=False,
657-
):
653+
@cbook._rename_parameter("3.3", "nonpos", "nonpositive")
654+
def __init__(self, axis, nonpositive='mask', *,
655+
one_half=r"\frac{1}{2}", use_overline=False):
658656
r"""
659657
Parameters
660658
----------
661659
axis : `matplotlib.axis.Axis`
662660
Currently unused.
663-
nonpos : {'mask', 'clip'}
661+
nonpositive : {'mask', 'clip'}
664662
Determines the behavior for values beyond the open interval ]0, 1[.
665663
They can either be masked as invalid, or clipped to a number very
666664
close to 0 or 1.
@@ -670,7 +668,7 @@ def __init__(
670668
one_half : str, default: r"\frac{1}{2}"
671669
The string used for ticks formatter to represent 1/2.
672670
"""
673-
self._transform = LogitTransform(nonpos)
671+
self._transform = LogitTransform(nonpositive)
674672
self._use_overline = use_overline
675673
self._one_half = one_half
676674

lib/matplotlib/tests/test_axes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5683,15 +5683,15 @@ def test_loglog_nonpos(new_api):
56835683
if new_api:
56845684
if mcx == mcy:
56855685
if mcx:
5686-
ax.loglog(x, y**3, lw=2, nonpos=mcx)
5686+
ax.loglog(x, y**3, lw=2, nonpositive=mcx)
56875687
else:
56885688
ax.loglog(x, y**3, lw=2)
56895689
else:
56905690
ax.loglog(x, y**3, lw=2)
56915691
if mcx:
5692-
ax.set_xscale("log", nonpos=mcx)
5692+
ax.set_xscale("log", nonpositive=mcx)
56935693
if mcy:
5694-
ax.set_yscale("log", nonpos=mcy)
5694+
ax.set_yscale("log", nonpositive=mcy)
56955695
else:
56965696
kws = {}
56975697
if mcx:

lib/matplotlib/tests/test_scale.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from matplotlib.cbook import MatplotlibDeprecationWarning
22
import matplotlib.pyplot as plt
3-
from matplotlib.scale import (Log10Transform, InvertedLog10Transform,
4-
SymmetricalLogTransform)
3+
from matplotlib.scale import (
4+
LogTransform, Log10Transform, InvertedLog10Transform,
5+
SymmetricalLogTransform)
56
from matplotlib.testing.decorators import check_figures_equal, image_comparison
67

78
import numpy as np
@@ -132,11 +133,8 @@ def test_logscale_invert_transform():
132133
def test_logscale_transform_repr():
133134
fig, ax = plt.subplots()
134135
ax.set_yscale('log')
135-
repr(ax.transData) # check that repr of log transform succeeds
136-
137-
# check that repr of log transform succeeds
138-
with pytest.warns(MatplotlibDeprecationWarning):
139-
repr(Log10Transform(nonpos='clip'))
136+
repr(ax.transData)
137+
repr(LogTransform(10, nonpositive='clip'))
140138

141139

142140
@image_comparison(['logscale_nonpos_values.png'],
@@ -148,7 +146,7 @@ def test_logscale_nonpos_values():
148146
ax1.hist(xs, range=(-5, 5), bins=10)
149147
ax1.set_yscale('log')
150148
ax2.hist(xs, range=(-5, 5), bins=10)
151-
ax2.set_yscale('log', nonpos='mask')
149+
ax2.set_yscale('log', nonpositive='mask')
152150

153151
xdata = np.arange(0, 10, 0.01)
154152
ydata = np.exp(-xdata)

0 commit comments

Comments
 (0)