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

Skip to content

Commit dee07b2

Browse files
committed
Also change the kwarg names on semilogx/y and loglog.
1 parent a4c017c commit dee07b2

File tree

3 files changed

+76
-50
lines changed

3 files changed

+76
-50
lines changed

doc/api/next_api_changes/deprecations.rst

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,14 @@ variables is deprecated. Additional fonts may be registered using
174174
~~~~~~~~~~~~~~~~~~~~~
175175
This module is deprecated.
176176

177-
Signature of `.LogScale` and `.SymmetricalLogScale`
178-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
179-
These classes used to take keyword arguments that depends on the axis
180-
orientation ("basex" vs "basey", "nonposx" vs "nonposy"); these parameter
181-
names are now deprecated in favor of "base", "nonpos", etc. This deprecation
182-
also affects e.g. ``ax.set_yscale("log", basey=...)`` which must now be
183-
spelled ``ax.set_yscale("log", base=...)``. The only place where "basex", etc.
184-
remain in use is in the helper functions `~.Axes.loglog`, `~.Axes.semilogx`,
185-
and `~.Axes.semilogy` (because `~.Axes.loglog` takes both "basex" and "basey").
177+
log/symlog scale base, ticks, and nonpos specification
178+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
179+
`~.Axes.semilogx`, `~.Axes.semilogy`, `~.Axes.loglog`, `.LogScale`, and
180+
`.SymmetricalLogScale` used to take keyword arguments that depends on the axis
181+
orientation ("basex" vs "basey", "nonposx" vs "nonposy"); these parameter names
182+
are now deprecated in favor of "base", "nonpos", etc. This deprecation also
183+
affects e.g. ``ax.set_yscale("log", basey=...)`` which must now be spelled
184+
``ax.set_yscale("log", base=...)``.
185+
186+
To use *different* bases for the x-axis and y-axei of a `~.Axes.loglog` plot,
187+
use e.g. ``ax.set_xscale("log", base=10); ax.set_yscale("log", base=2)``.

lib/matplotlib/axes/_axes.py

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,24 +1766,25 @@ 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 *basex/y*, *subsx/y* and *nonposx/y* control
1770-
the x/y-axis properties. They are just forwarded to `.Axes.set_xscale`
1771-
and `.Axes.set_yscale`.
1769+
The additional parameters *base*, *subs* and *nonpos* control the
1770+
x/y-axis properties. They are just forwarded to `.Axes.set_xscale` and
1771+
`.Axes.set_yscale`. To use different properties on the x-axis and the
1772+
y-axis, use e.g.
1773+
``ax.set_xscale("log", base=10); ax.set_yscale("log", base=2)``.
17721774
17731775
Parameters
17741776
----------
1775-
basex, basey : float, default: 10
1776-
Base of the x/y logarithm.
1777+
base : float, default: 10
1778+
Base of the logarithm.
17771779
1778-
subsx, subsy : sequence, optional
1779-
The location of the minor x/y ticks. If *None*, reasonable
1780-
locations are automatically chosen depending on the number of
1781-
decades in the plot.
1782-
See `.Axes.set_xscale` / `.Axes.set_yscale` for details.
1780+
subs : sequence, optional
1781+
The location of the minor ticks. If *None*, reasonable locations
1782+
are automatically chosen depending on the number of decades in the
1783+
plot. See `.Axes.set_xscale`/`.Axes.set_yscale` for details.
17831784
1784-
nonposx, nonposy : {'mask', 'clip'}, default: 'mask'
1785-
Non-positive values in x or y can be masked as invalid, or clipped
1786-
to a very small positive number.
1785+
nonpos : {'mask', 'clip'}, default: 'mask'
1786+
Non-positive values can be masked as invalid, or clipped to a very
1787+
small positive number.
17871788
17881789
Returns
17891790
-------
@@ -1795,13 +1796,14 @@ def loglog(self, *args, **kwargs):
17951796
**kwargs
17961797
All parameters supported by `.plot`.
17971798
"""
1798-
dx = {k[:-1]: kwargs.pop(k) for k in ['basex', 'subsx', 'nonposx']
1799-
if k in kwargs}
1799+
dx = {k: v for k, v in kwargs.items()
1800+
if k in ['base', 'subs', 'nonpos', 'basex', 'subsx', 'nonposx']}
18001801
self.set_xscale('log', **dx)
1801-
dy = {k[:-1]: kwargs.pop(k) for k in ['basey', 'subsy', 'nonposy']
1802-
if k in kwargs}
1802+
dy = {k: v for k, v in kwargs.items()
1803+
if k in ['base', 'subs', 'nonpos', 'basey', 'subsy', 'nonposy']}
18031804
self.set_yscale('log', **dy)
1804-
return self.plot(*args, **kwargs)
1805+
return self.plot(
1806+
*args, **{k: v for k, v in kwargs.items() if k not in {*dx, *dy}})
18051807

18061808
# @_preprocess_data() # let 'plot' do the unpacking..
18071809
@docstring.dedent_interpd
@@ -1818,20 +1820,20 @@ def semilogx(self, *args, **kwargs):
18181820
the x-axis to log scaling. All of the concepts and parameters of plot
18191821
can be used here as well.
18201822
1821-
The additional parameters *basex*, *subsx* and *nonposx* control the
1823+
The additional parameters *base*, *subs*, and *nonpos* control the
18221824
x-axis properties. They are just forwarded to `.Axes.set_xscale`.
18231825
18241826
Parameters
18251827
----------
1826-
basex : float, default: 10
1828+
base : float, default: 10
18271829
Base of the x logarithm.
18281830
1829-
subsx : array-like, optional
1831+
subs : array-like, optional
18301832
The location of the minor xticks. If *None*, reasonable locations
18311833
are automatically chosen depending on the number of decades in the
18321834
plot. See `.Axes.set_xscale` for details.
18331835
1834-
nonposx : {'mask', 'clip'}, default: 'mask'
1836+
nonpos : {'mask', 'clip'}, default: 'mask'
18351837
Non-positive values in x can be masked as invalid, or clipped to a
18361838
very small positive number.
18371839
@@ -1845,10 +1847,11 @@ def semilogx(self, *args, **kwargs):
18451847
**kwargs
18461848
All parameters supported by `.plot`.
18471849
"""
1848-
d = {k[:-1]: kwargs.pop(k) for k in ['basex', 'subsx', 'nonposx']
1849-
if k in kwargs}
1850+
d = {k: v for k, v in kwargs.items()
1851+
if k in ['base', 'subs', 'nonpos', 'basex', 'subsx', 'nonposx']}
18501852
self.set_xscale('log', **d)
1851-
return self.plot(*args, **kwargs)
1853+
return self.plot(
1854+
*args, **{k: v for k, v in kwargs.items() if k not in d})
18521855

18531856
# @_preprocess_data() # let 'plot' do the unpacking..
18541857
@docstring.dedent_interpd
@@ -1865,20 +1868,20 @@ def semilogy(self, *args, **kwargs):
18651868
the y-axis to log scaling. All of the concepts and parameters of plot
18661869
can be used here as well.
18671870
1868-
The additional parameters *basey*, *subsy* and *nonposy* control the
1871+
The additional parameters *base*, *subs*, and *nonpos* control the
18691872
y-axis properties. They are just forwarded to `.Axes.set_yscale`.
18701873
18711874
Parameters
18721875
----------
1873-
basey : float, default: 10
1876+
base : float, default: 10
18741877
Base of the y logarithm.
18751878
1876-
subsy : array-like, optional
1879+
subs : array-like, optional
18771880
The location of the minor yticks. If *None*, reasonable locations
18781881
are automatically chosen depending on the number of decades in the
18791882
plot. See `.Axes.set_yscale` for details.
18801883
1881-
nonposy : {'mask', 'clip'}, default: 'mask'
1884+
nonpos : {'mask', 'clip'}, default: 'mask'
18821885
Non-positive values in y can be masked as invalid, or clipped to a
18831886
very small positive number.
18841887
@@ -1892,10 +1895,11 @@ def semilogy(self, *args, **kwargs):
18921895
**kwargs
18931896
All parameters supported by `.plot`.
18941897
"""
1895-
d = {k[:-1]: kwargs.pop(k) for k in ['basey', 'subsy', 'nonposy']
1896-
if k in kwargs}
1898+
d = {k: v for k, v in kwargs.items()
1899+
if k in ['base', 'subs', 'nonpos', 'basey', 'subsy', 'nonposy']}
18971900
self.set_yscale('log', **d)
1898-
return self.plot(*args, **kwargs)
1901+
return self.plot(
1902+
*args, **{k: v for k, v in kwargs.items() if k not in d})
18991903

19001904
@_preprocess_data(replace_names=["x"], label_namer="x")
19011905
def acorr(self, x, **kwargs):

lib/matplotlib/tests/test_axes.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
from collections import namedtuple
2-
from itertools import product
2+
import datetime
3+
from decimal import Decimal
34
import io
5+
from itertools import product
46
import platform
5-
6-
import datetime
7+
try:
8+
from contextlib import nullcontext
9+
except ImportError:
10+
from contextlib import ExitStack as nullcontext # Py3.6.
711

812
import dateutil.tz as dutz
913

1014
import numpy as np
1115
from numpy import ma
1216
from cycler import cycler
13-
from decimal import Decimal
1417
import pytest
1518

1619
import matplotlib
@@ -5661,21 +5664,38 @@ def test_loglog():
56615664
ax.tick_params(length=15, width=2, which='minor')
56625665

56635666

5667+
@pytest.mark.parametrize("new_api", [False, True])
56645668
@image_comparison(["test_loglog_nonpos.png"], remove_text=True, style='mpl20')
5665-
def test_loglog_nonpos():
5666-
fig, ax = plt.subplots(3, 3)
5669+
def test_loglog_nonpos(new_api):
5670+
fig, axs = plt.subplots(3, 3)
56675671
x = np.arange(1, 11)
56685672
y = x**3
56695673
y[7] = -3.
56705674
x[4] = -10
5671-
for nn, mcx in enumerate(['mask', 'clip', '']):
5672-
for mm, mcy in enumerate(['mask', 'clip', '']):
5675+
for (i, j), ax in np.ndenumerate(axs):
5676+
mcx = ['mask', 'clip', ''][j]
5677+
mcy = ['mask', 'clip', ''][i]
5678+
if new_api:
5679+
if mcx == mcy:
5680+
if mcx:
5681+
ax.loglog(x, y**3, lw=2, nonpos=mcx)
5682+
else:
5683+
ax.loglog(x, y**3, lw=2)
5684+
else:
5685+
ax.loglog(x, y**3, lw=2)
5686+
if mcx:
5687+
ax.set_xscale("log", nonpos=mcx)
5688+
if mcy:
5689+
ax.set_yscale("log", nonpos=mcy)
5690+
else:
56735691
kws = {}
56745692
if mcx:
56755693
kws['nonposx'] = mcx
56765694
if mcy:
56775695
kws['nonposy'] = mcy
5678-
ax[mm, nn].loglog(x, y**3, lw=2, **kws)
5696+
with (pytest.warns(MatplotlibDeprecationWarning) if kws
5697+
else nullcontext()):
5698+
ax.loglog(x, y**3, lw=2, **kws)
56795699

56805700

56815701
@pytest.mark.style('default')

0 commit comments

Comments
 (0)