Skip to content

Commit 2653ce8

Browse files
authored
Merge pull request #10278 from timhoffm/axes-doc-log
DOC: improve docstring of Axes.loglog, Axes.semilogx, Axes.semilogy
2 parents 95497a6 + 4d5df41 commit 2653ce8

File tree

2 files changed

+80
-66
lines changed

2 files changed

+80
-66
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 78 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ def plot(self, *args, **kwargs):
14151415
Returns
14161416
-------
14171417
lines
1418-
A list of `.Line2D` objects that were added.
1418+
A list of `.Line2D` objects representing the plotted data.
14191419
14201420
14211421
See Also
@@ -1558,7 +1558,7 @@ def plot_date(self, x, y, fmt='o', tz=None, xdate=True, ydate=False,
15581558
Returns
15591559
-------
15601560
lines
1561-
A list of `.Line2D` objects that were added to the axes.
1561+
A list of `~.Line2D` objects representing the plotted data.
15621562
15631563
15641564
Other Parameters
@@ -1607,36 +1607,45 @@ def plot_date(self, x, y, fmt='o', tz=None, xdate=True, ydate=False,
16071607
@docstring.dedent_interpd
16081608
def loglog(self, *args, **kwargs):
16091609
"""
1610-
Make a plot with log scaling on both the *x* and *y* axis.
1610+
Make a plot with log scaling on both the x and y axis.
1611+
1612+
Call signatures::
16111613
1612-
:func:`~matplotlib.pyplot.loglog` supports all the keyword
1613-
arguments of :func:`~matplotlib.pyplot.plot` and
1614-
:meth:`matplotlib.axes.Axes.set_xscale` /
1615-
:meth:`matplotlib.axes.Axes.set_yscale`.
1614+
loglog([x], y, [fmt], data=None, **kwargs)
1615+
loglog([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs)
1616+
1617+
This is just a thin wrapper around `.plot` which additionally changes
1618+
both the x-axis and the y-axis to log scaling. All of the concepts and
1619+
parameters of plot can be used here as well.
1620+
1621+
The additional parameters *basex/y*, *subsx/y* and *nonposx/y* control
1622+
the x/y-axis properties. They are just forwarded to `.Axes.set_xscale`
1623+
and `.Axes.set_yscale`.
16161624
16171625
Parameters
16181626
----------
1619-
basex, basey : scalar
1620-
Base of the x/y logarithm. Must be > 1.
1627+
basex, basey : scalar, optional, default 10
1628+
Base of the x/y logarithm.
16211629
1622-
subsx, subsy : sequence
1623-
The location of the minor x/y ticks; ``None`` defaults to autosubs,
1624-
which depend on the number of decades in the plot;
1625-
see :meth:`matplotlib.axes.Axes.set_xscale` /
1626-
:meth:`matplotlib.axes.Axes.set_yscale` for details.
1630+
subsx, subsy : sequence, optional
1631+
The location of the minor x/y ticks. If *None*, reasonable
1632+
locations are automatically chosen depending on the number of
1633+
decades in the plot.
1634+
See `.Axes.set_xscale` / `.Axes.set_yscale` for details.
16271635
1628-
nonposx, nonposy : ['mask' | 'clip' ]
1636+
nonposx, nonposy : {'mask', 'clip'}, optional, default 'mask'
16291637
Non-positive values in x or y can be masked as invalid, or clipped
16301638
to a very small positive number.
16311639
1640+
Returns
1641+
-------
1642+
lines
1643+
A list of `~.Line2D` objects representing the plotted data.
1644+
16321645
Other Parameters
16331646
----------------
1634-
**kwargs :
1635-
The remaining valid kwargs are :class:`~matplotlib.lines.Line2D`
1636-
properties:
1637-
1638-
%(Line2D)s
1639-
1647+
**kwargs
1648+
All parameters supported by `.plot`.
16401649
"""
16411650
if not self._hold:
16421651
self.cla()
@@ -1662,39 +1671,41 @@ def semilogx(self, *args, **kwargs):
16621671
"""
16631672
Make a plot with log scaling on the x axis.
16641673
1674+
Call signatures::
1675+
1676+
semilogx([x], y, [fmt], data=None, **kwargs)
1677+
semilogx([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs)
1678+
1679+
This is just a thin wrapper around `.plot` which additionally changes
1680+
the x-axis to log scaling. All of the concepts and parameters of plot
1681+
can be used here as well.
1682+
1683+
The additional parameters *basex*, *subsx* and *nonposx* control the
1684+
x-axis properties. They are just forwarded to `.Axes.set_xscale`.
1685+
16651686
Parameters
16661687
----------
1667-
basex : float, optional
1668-
Base of the x logarithm. The scalar should be larger than 1.
1688+
basex : scalar, optional, default 10
1689+
Base of the x logarithm.
16691690
16701691
subsx : array_like, optional
1671-
The location of the minor xticks; ``None`` defaults to
1672-
autosubs, which depend on the number of decades in the
1673-
plot; see :meth:`~matplotlib.axes.Axes.set_xscale` for
1674-
details.
1692+
The location of the minor xticks. If *None*, reasonable locations
1693+
are automatically chosen depending on the number of decades in the
1694+
plot. See `.Axes.set_xscale` for details.
16751695
1676-
nonposx : string, optional, {'mask', 'clip'}
1677-
Non-positive values in x can be masked as
1678-
invalid, or clipped to a very small positive number.
1696+
nonposx : {'mask', 'clip'}, optional, default 'mask'
1697+
Non-positive values in x can be masked as invalid, or clipped to a
1698+
very small positive number.
16791699
16801700
Returns
16811701
-------
1682-
`~matplotlib.pyplot.plot`
1683-
Log-scaled plot on the x axis.
1702+
lines
1703+
A list of `~.Line2D` objects representing the plotted data.
16841704
16851705
Other Parameters
16861706
----------------
1687-
**kwargs :
1688-
Keyword arguments control the :class:`~matplotlib.lines.Line2D`
1689-
properties:
1690-
1691-
%(Line2D)s
1692-
1693-
Notes
1694-
-----
1695-
This function supports all the keyword arguments of
1696-
:func:`~matplotlib.pyplot.plot` and
1697-
:meth:`matplotlib.axes.Axes.set_xscale`.
1707+
**kwargs
1708+
All parameters supported by `.plot`.
16981709
"""
16991710
if not self._hold:
17001711
self.cla()
@@ -1714,41 +1725,42 @@ def semilogy(self, *args, **kwargs):
17141725
"""
17151726
Make a plot with log scaling on the y axis.
17161727
1728+
Call signatures::
1729+
1730+
semilogy([x], y, [fmt], data=None, **kwargs)
1731+
semilogy([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs)
1732+
1733+
This is just a thin wrapper around `.plot` which additionally changes
1734+
the y-axis to log scaling. All of the concepts and parameters of plot
1735+
can be used here as well.
1736+
1737+
The additional parameters *basey*, *subsy* and *nonposy* control the
1738+
y-axis properties. They are just forwarded to `.Axes.set_yscale`.
1739+
17171740
Parameters
17181741
----------
1719-
basey : float, optional
1720-
Base of the y logarithm. The scalar should be larger than 1.
1742+
basey : scalar, optional, default 10
1743+
Base of the y logarithm.
17211744
17221745
subsy : array_like, optional
1723-
The location of the minor yticks; ``None`` defaults to
1724-
autosubs, which depend on the number of decades in the
1725-
plot; see :meth:`~matplotlib.axes.Axes.set_yscale` for
1726-
details.
1746+
The location of the minor yticks. If *None*, reasonable locations
1747+
are automatically chosen depending on the number of decades in the
1748+
plot. See `.Axes.set_yscale` for details.
17271749
1728-
nonposy : string, optional, {'mask', 'clip'}
1729-
Non-positive values in *y* can be masked as
1730-
invalid, or clipped to a very small positive number.
1750+
nonposy : {'mask', 'clip'}, optional, default 'mask'
1751+
Non-positive values in y can be masked as invalid, or clipped to a
1752+
very small positive number.
17311753
17321754
Returns
17331755
-------
1734-
`~matplotlib.pyplot.plot`
1735-
Log-scaled plot on the *y* axis.
1756+
lines
1757+
A list of `~.Line2D` objects representing the plotted data.
17361758
17371759
Other Parameters
17381760
----------------
1739-
**kwargs :
1740-
Keyword arguments control the :class:`~matplotlib.lines.Line2D`
1741-
properties:
1742-
1743-
%(Line2D)s
1744-
1745-
Notes
1746-
-----
1747-
This function supports all the keyword arguments of
1748-
:func:`~matplotlib.pyplot.plot` and
1749-
:meth:`matplotlib.axes.Axes.set_yscale`.
1761+
**kwargs
1762+
All parameters supported by `.plot`.
17501763
"""
1751-
17521764
if not self._hold:
17531765
self.cla()
17541766
d = {k: kwargs.pop(k) for k in ['basey', 'subsy', 'nonposy']

lib/matplotlib/scale.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ def __init__(self, axis, **kwargs):
254254

255255
if nonpos not in ['mask', 'clip']:
256256
raise ValueError("nonposx, nonposy kwarg must be 'mask' or 'clip'")
257+
if base <= 0 or base == 1:
258+
raise ValueError('The log base cannot be <= 0 or == 1')
257259

258260
if base == 10.0:
259261
self._transform = self.Log10Transform(nonpos)

0 commit comments

Comments
 (0)