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

Skip to content

Make kwargs names in scale.py not include the axis direction. #14916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions doc/api/next_api_changes/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,18 @@ Debian 8 (2015, EOL 06/2020) and Ubuntu 14.04 (EOL 04/2019) were the
last versions of Debian and Ubuntu to ship avconv. It remains possible
to force the use of avconv by using the ffmpeg-based writers with
:rc:`animation.ffmpeg_path` set to "avconv".

log/symlog scale base, ticks, and nonpos specification
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`~.Axes.semilogx`, `~.Axes.semilogy`, `~.Axes.loglog`, `.LogScale`, and
`.SymmetricalLogScale` used to take keyword arguments that depends on the axis
orientation ("basex" vs "basey", "subsx" vs "subsy", "nonposx" vs "nonposy");
these parameter names are now deprecated in favor of "base", "subs",
"nonpositive". This deprecation also affects e.g. ``ax.set_yscale("log",
basey=...)`` which must now be spelled ``ax.set_yscale("log", base=...)``.

The change from "nonpos" to "nonpositive" also affects `~.scale.LogTransform`,
`~.scale.InvertedLogTransform`, `~.scale.SymmetricalLogTransform`, etc.

To use *different* bases for the x-axis and y-axis of a `~.Axes.loglog` plot,
use e.g. ``ax.set_xscale("log", base=10); ax.set_yscale("log", base=2)``.
7 changes: 4 additions & 3 deletions examples/scales/log_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
ax2.grid()

# log x and y axis
ax3.loglog(t, 20 * np.exp(-t / 10.0), basex=2)
ax3.loglog(t, 20 * np.exp(-t / 10.0))
ax3.set_xscale('log', base=2)
ax3.set(title='loglog base 2 on x')
ax3.grid()

Expand All @@ -35,8 +36,8 @@
x = 10.0**np.linspace(0.0, 2.0, 20)
y = x**2.0

ax4.set_xscale("log", nonposx='clip')
ax4.set_yscale("log", nonposy='clip')
ax4.set_xscale("log", nonpositive='clip')
ax4.set_yscale("log", nonpositive='clip')
ax4.set(title='Errorbars go negative')
ax4.errorbar(x, y, xerr=0.1 * x, yerr=5.0 + 0.75 * y)
# ylim must be set after errorbar to allow errorbar to autoscale limits
Expand Down
2 changes: 1 addition & 1 deletion examples/scales/scales.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
# symmetric log
ax = axs[1, 1]
ax.plot(x, y - y.mean())
ax.set_yscale('symlog', linthreshy=0.02)
ax.set_yscale('symlog', linthresh=0.02)
ax.set_title('symlog')
ax.grid(True)

Expand Down
2 changes: 1 addition & 1 deletion examples/scales/symlog_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
plt.subplot(313)
plt.plot(x, np.sin(x / 3.0))
plt.xscale('symlog')
plt.yscale('symlog', linthreshy=0.015)
plt.yscale('symlog', linthresh=0.015)
plt.grid(True)
plt.ylabel('symlog both')

Expand Down
87 changes: 44 additions & 43 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1766,24 +1766,25 @@ def loglog(self, *args, **kwargs):
both the x-axis and the y-axis to log scaling. All of the concepts and
parameters of plot can be used here as well.

The additional parameters *basex/y*, *subsx/y* and *nonposx/y* control
the x/y-axis properties. They are just forwarded to `.Axes.set_xscale`
and `.Axes.set_yscale`.
The additional parameters *base*, *subs* and *nonpositive* control the
x/y-axis properties. They are just forwarded to `.Axes.set_xscale` and
`.Axes.set_yscale`. To use different properties on the x-axis and the
y-axis, use e.g.
``ax.set_xscale("log", base=10); ax.set_yscale("log", base=2)``.

Parameters
----------
basex, basey : float, default: 10
Base of the x/y logarithm.
base : float, default: 10
Base of the logarithm.

subsx, subsy : sequence, optional
The location of the minor x/y ticks. If *None*, reasonable
locations are automatically chosen depending on the number of
decades in the plot.
See `.Axes.set_xscale` / `.Axes.set_yscale` for details.
subs : sequence, optional
The location of the minor ticks. If *None*, reasonable locations
are automatically chosen depending on the number of decades in the
plot. See `.Axes.set_xscale`/`.Axes.set_yscale` for details.

nonposx, nonposy : {'mask', 'clip'}, default: 'mask'
Non-positive values in x or y can be masked as invalid, or clipped
to a very small positive number.
nonpositive : {'mask', 'clip'}, default: 'mask'
Non-positive values can be masked as invalid, or clipped to a very
small positive number.

Returns
-------
Expand All @@ -1795,16 +1796,16 @@ def loglog(self, *args, **kwargs):
**kwargs
All parameters supported by `.plot`.
"""
dx = {k: kwargs.pop(k) for k in ['basex', 'subsx', 'nonposx']
if k in kwargs}
dy = {k: kwargs.pop(k) for k in ['basey', 'subsy', 'nonposy']
if k in kwargs}

dx = {k: v for k, v in kwargs.items()
if k in ['base', 'subs', 'nonpositive',
'basex', 'subsx', 'nonposx']}
self.set_xscale('log', **dx)
dy = {k: v for k, v in kwargs.items()
if k in ['base', 'subs', 'nonpositive',
'basey', 'subsy', 'nonposy']}
self.set_yscale('log', **dy)

l = self.plot(*args, **kwargs)
return l
return self.plot(
*args, **{k: v for k, v in kwargs.items() if k not in {*dx, *dy}})

# @_preprocess_data() # let 'plot' do the unpacking..
@docstring.dedent_interpd
Expand All @@ -1821,20 +1822,20 @@ def semilogx(self, *args, **kwargs):
the x-axis to log scaling. All of the concepts and parameters of plot
can be used here as well.

The additional parameters *basex*, *subsx* and *nonposx* control the
The additional parameters *base*, *subs*, and *nonpositive* control the
x-axis properties. They are just forwarded to `.Axes.set_xscale`.

Parameters
----------
basex : float, default: 10
base : float, default: 10
Base of the x logarithm.

subsx : array-like, optional
subs : array-like, optional
The location of the minor xticks. If *None*, reasonable locations
are automatically chosen depending on the number of decades in the
plot. See `.Axes.set_xscale` for details.

nonposx : {'mask', 'clip'}, default: 'mask'
nonpositive : {'mask', 'clip'}, default: 'mask'
Non-positive values in x can be masked as invalid, or clipped to a
very small positive number.

Expand All @@ -1848,12 +1849,12 @@ def semilogx(self, *args, **kwargs):
**kwargs
All parameters supported by `.plot`.
"""
d = {k: kwargs.pop(k) for k in ['basex', 'subsx', 'nonposx']
if k in kwargs}

d = {k: v for k, v in kwargs.items()
if k in ['base', 'subs', 'nonpositive',
'basex', 'subsx', 'nonposx']}
self.set_xscale('log', **d)
l = self.plot(*args, **kwargs)
return l
return self.plot(
*args, **{k: v for k, v in kwargs.items() if k not in d})

# @_preprocess_data() # let 'plot' do the unpacking..
@docstring.dedent_interpd
Expand All @@ -1870,20 +1871,20 @@ def semilogy(self, *args, **kwargs):
the y-axis to log scaling. All of the concepts and parameters of plot
can be used here as well.

The additional parameters *basey*, *subsy* and *nonposy* control the
The additional parameters *base*, *subs*, and *nonpositive* control the
y-axis properties. They are just forwarded to `.Axes.set_yscale`.

Parameters
----------
basey : float, default: 10
base : float, default: 10
Base of the y logarithm.

subsy : array-like, optional
subs : array-like, optional
The location of the minor yticks. If *None*, reasonable locations
are automatically chosen depending on the number of decades in the
plot. See `.Axes.set_yscale` for details.

nonposy : {'mask', 'clip'}, default: 'mask'
nonpositive : {'mask', 'clip'}, default: 'mask'
Non-positive values in y can be masked as invalid, or clipped to a
very small positive number.

Expand All @@ -1897,12 +1898,12 @@ def semilogy(self, *args, **kwargs):
**kwargs
All parameters supported by `.plot`.
"""
d = {k: kwargs.pop(k) for k in ['basey', 'subsy', 'nonposy']
if k in kwargs}
d = {k: v for k, v in kwargs.items()
if k in ['base', 'subs', 'nonpositive',
'basey', 'subsy', 'nonposy']}
self.set_yscale('log', **d)
l = self.plot(*args, **kwargs)

return l
return self.plot(
*args, **{k: v for k, v in kwargs.items() if k not in d})

@_preprocess_data(replace_names=["x"], label_namer="x")
def acorr(self, x, **kwargs):
Expand Down Expand Up @@ -2343,11 +2344,11 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
if orientation == 'vertical':
self._process_unit_info(xdata=x, ydata=height, kwargs=kwargs)
if log:
self.set_yscale('log', nonposy='clip')
self.set_yscale('log', nonpositive='clip')
elif orientation == 'horizontal':
self._process_unit_info(xdata=width, ydata=y, kwargs=kwargs)
if log:
self.set_xscale('log', nonposx='clip')
self.set_xscale('log', nonpositive='clip')

# lets do some conversions now since some types cannot be
# subtracted uniformly
Expand Down Expand Up @@ -6715,9 +6716,9 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,

if log:
if orientation == 'horizontal':
self.set_xscale('log', nonposx='clip')
self.set_xscale('log', nonpositive='clip')
else: # orientation == 'vertical'
self.set_yscale('log', nonposy='clip')
self.set_yscale('log', nonpositive='clip')

if align == 'left':
x -= 0.5*(bins[1]-bins[0])
Expand Down
Loading