Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit82ee63e

Browse files
committed
Also change the kwarg names on semilogx/y and loglog.
1 parent2c03e25 commit82ee63e

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
@@ -185,12 +185,14 @@ last versions of Debian and Ubuntu to ship avconv. It remains possible
185185
to force the use of avconv by using the ffmpeg-based writers with
186186
:rc:`animation.ffmpeg_path` set to "avconv".
187187

188-
Signature of `.LogScale` and `.SymmetricalLogScale`
189-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
190-
These classes used to take keyword arguments that depends on the axis
191-
orientation ("basex" vs "basey", "nonposx" vs "nonposy"); these parameter
192-
names are now deprecated in favor of "base", "nonpos", etc. This deprecation
193-
also affects e.g. ``ax.set_yscale("log", basey=...)`` which must now be
194-
spelled ``ax.set_yscale("log", base=...)``. The only place where "basex", etc.
195-
remain in use is in the helper functions `~.Axes.loglog`, `~.Axes.semilogx`,
196-
and `~.Axes.semilogy` (because `~.Axes.loglog` takes both "basex" and "basey").
188+
log/symlog scale base, ticks, and nonpos specification
189+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
190+
`~.Axes.semilogx`, `~.Axes.semilogy`, `~.Axes.loglog`, `.LogScale`, and
191+
`.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=...)``.
196+
197+
To use *different* bases for the x-axis and y-axei of a `~.Axes.loglog` plot,
198+
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 thex/ylogarithm.
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 valuesin x or ycan be masked as invalid, or clipped
1786-
to a verysmall 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)forkin ['basex','subsx','nonposx']
1799-
ifkinkwargs}
1799+
dx= {k:vfork,vinkwargs.items()
1800+
ifkin['base','subs','nonpos','basex','subsx','nonposx']}
18001801
self.set_xscale('log',**dx)
1801-
dy= {k[:-1]:kwargs.pop(k)forkin ['basey','subsy','nonposy']
1802-
ifkinkwargs}
1802+
dy= {k:vfork,vinkwargs.items()
1803+
ifkin['base','subs','nonpos','basey','subsy','nonposy']}
18031804
self.set_yscale('log',**dy)
1804-
returnself.plot(*args,**kwargs)
1805+
returnself.plot(
1806+
*args,**{k:vfork,vinkwargs.items()ifknotin {*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)forkin ['basex','subsx','nonposx']
1849-
ifkinkwargs}
1850+
d= {k:vfork,vinkwargs.items()
1851+
ifkin['base','subs','nonpos','basex','subsx','nonposx']}
18501852
self.set_xscale('log',**d)
1851-
returnself.plot(*args,**kwargs)
1853+
returnself.plot(
1854+
*args,**{k:vfork,vinkwargs.items()ifknotind})
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)forkin ['basey','subsy','nonposy']
1896-
ifkinkwargs}
1898+
d= {k:vfork,vinkwargs.items()
1899+
ifkin['base','subs','nonpos','basey','subsy','nonposy']}
18971900
self.set_yscale('log',**d)
1898-
returnself.plot(*args,**kwargs)
1901+
returnself.plot(
1902+
*args,**{k:vfork,vinkwargs.items()ifknotind})
18991903

19001904
@_preprocess_data(replace_names=["x"],label_namer="x")
19011905
defacorr(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
fromcollectionsimportnamedtuple
2-
fromitertoolsimportproduct
2+
importdatetime
3+
fromdecimalimportDecimal
34
importio
5+
fromitertoolsimportproduct
46
importplatform
5-
6-
importdatetime
7+
try:
8+
fromcontextlibimportnullcontext
9+
exceptImportError:
10+
fromcontextlibimportExitStackasnullcontext# Py3.6.
711

812
importdateutil.tzasdutz
913

1014
importnumpyasnp
1115
fromnumpyimportma
1216
fromcyclerimportcycler
13-
fromdecimalimportDecimal
1417
importpytest
1518

1619
importmatplotlib
@@ -5666,21 +5669,38 @@ def test_loglog():
56665669
ax.tick_params(length=15,width=2,which='minor')
56675670

56685671

5672+
@pytest.mark.parametrize("new_api", [False,True])
56695673
@image_comparison(["test_loglog_nonpos.png"],remove_text=True,style='mpl20')
5670-
deftest_loglog_nonpos():
5671-
fig,ax=plt.subplots(3,3)
5674+
deftest_loglog_nonpos(new_api):
5675+
fig,axs=plt.subplots(3,3)
56725676
x=np.arange(1,11)
56735677
y=x**3
56745678
y[7]=-3.
56755679
x[4]=-10
5676-
fornn,mcxinenumerate(['mask','clip','']):
5677-
formm,mcyinenumerate(['mask','clip','']):
5680+
for (i,j),axinnp.ndenumerate(axs):
5681+
mcx= ['mask','clip',''][j]
5682+
mcy= ['mask','clip',''][i]
5683+
ifnew_api:
5684+
ifmcx==mcy:
5685+
ifmcx:
5686+
ax.loglog(x,y**3,lw=2,nonpos=mcx)
5687+
else:
5688+
ax.loglog(x,y**3,lw=2)
5689+
else:
5690+
ax.loglog(x,y**3,lw=2)
5691+
ifmcx:
5692+
ax.set_xscale("log",nonpos=mcx)
5693+
ifmcy:
5694+
ax.set_yscale("log",nonpos=mcy)
5695+
else:
56785696
kws= {}
56795697
ifmcx:
56805698
kws['nonposx']=mcx
56815699
ifmcy:
56825700
kws['nonposy']=mcy
5683-
ax[mm,nn].loglog(x,y**3,lw=2,**kws)
5701+
with (pytest.warns(MatplotlibDeprecationWarning)ifkws
5702+
elsenullcontext()):
5703+
ax.loglog(x,y**3,lw=2,**kws)
56845704

56855705

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp