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

Skip to content

Commit fb6e599

Browse files
authored
Merge pull request #10808 from matplotlib/auto-backport-of-pr-10296
Backport PR #10296 on branch v2.2.x
2 parents 75669ec + 798db39 commit fb6e599

File tree

2 files changed

+190
-85
lines changed

2 files changed

+190
-85
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,19 +210,20 @@ def get_xlabel(self):
210210

211211
def set_xlabel(self, xlabel, fontdict=None, labelpad=None, **kwargs):
212212
"""
213-
Set the label for the xaxis.
213+
Set the label for the x-axis.
214214
215215
Parameters
216216
----------
217-
xlabel : string
218-
x label
217+
xlabel : str
218+
The label text.
219219
220220
labelpad : scalar, optional, default: None
221-
spacing in points between the label and the x-axis
221+
Spacing in points between the label and the x-axis.
222222
223223
Other Parameters
224224
----------------
225-
**kwargs : `~matplotlib.text.Text` properties
225+
**kwargs : `.Text` properties
226+
`.Text` properties control the appearance of the label.
226227
227228
See also
228229
--------
@@ -241,19 +242,20 @@ def get_ylabel(self):
241242

242243
def set_ylabel(self, ylabel, fontdict=None, labelpad=None, **kwargs):
243244
"""
244-
Set the label for the yaxis
245+
Set the label for the y-axis.
245246
246247
Parameters
247248
----------
248-
ylabel : string
249-
y label
249+
ylabel : str
250+
The label text.
250251
251252
labelpad : scalar, optional, default: None
252-
spacing in points between the label and the y-axis
253+
Spacing in points between the label and the y-axis.
253254
254255
Other Parameters
255256
----------------
256-
**kwargs : `~matplotlib.text.Text` properties
257+
**kwargs : `.Text` properties
258+
`.Text` properties control the appearance of the label.
257259
258260
See also
259261
--------

lib/matplotlib/pyplot.py

Lines changed: 178 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,65 +1500,60 @@ def axis(*v, **kwargs):
15001500

15011501
def xlabel(s, *args, **kwargs):
15021502
"""
1503-
Set the *x* axis label of the current axis.
1503+
Set the x-axis label of the current axes.
15041504
1505-
Default override is::
1506-
1507-
override = {
1508-
'fontsize' : 'small',
1509-
'verticalalignment' : 'top',
1510-
'horizontalalignment' : 'center'
1511-
}
1505+
Call signature::
15121506
1513-
.. seealso::
1507+
xlabel(label, fontdict=None, labelpad=None, **kwargs)
15141508
1515-
:func:`~matplotlib.pyplot.text`
1516-
For information on how override and the optional args work
1509+
This is the pyplot equivalent of calling `.set_xlabel` on the current axes.
1510+
See there for a full parameter description.
15171511
"""
15181512
return gca().set_xlabel(s, *args, **kwargs)
15191513

15201514

15211515
def ylabel(s, *args, **kwargs):
15221516
"""
1523-
Set the *y* axis label of the current axis.
1517+
Set the y-axis label of the current axes.
15241518
1525-
Defaults override is::
1526-
1527-
override = {
1528-
'fontsize' : 'small',
1529-
'verticalalignment' : 'center',
1530-
'horizontalalignment' : 'right',
1531-
'rotation'='vertical' : }
1519+
Call signature::
15321520
1533-
.. seealso::
1521+
ylabel(label, fontdict=None, labelpad=None, **kwargs)
15341522
1535-
:func:`~matplotlib.pyplot.text`
1536-
For information on how override and the optional args
1537-
work.
1523+
This is the pyplot equivalent of calling `.set_ylabel` on the current axes.
1524+
See there for a full parameter description.
15381525
"""
15391526
return gca().set_ylabel(s, *args, **kwargs)
15401527

15411528

15421529
def xlim(*args, **kwargs):
15431530
"""
1544-
Get or set the *x* limits of the current axes.
1531+
Get or set the x limits of the current axes.
15451532
1546-
::
1533+
Call signatures::
15471534
1548-
xmin, xmax = xlim() # return the current xlim
1549-
xlim( (xmin, xmax) ) # set the xlim to xmin, xmax
1550-
xlim( xmin, xmax ) # set the xlim to xmin, xmax
1535+
xmin, xmax = xlim() # return the current xlim
1536+
xlim((xmin, xmax)) # set the xlim to xmin, xmax
1537+
xlim(xmin, xmax) # set the xlim to xmin, xmax
15511538
1552-
If you do not specify args, you can pass the xmin and xmax as
1553-
kwargs, e.g.::
1539+
If you do not specify args, you can pass *xmin* or *xmax* as kwargs, i.e.::
15541540
1555-
xlim(xmax=3) # adjust the max leaving min unchanged
1556-
xlim(xmin=1) # adjust the min leaving max unchanged
1541+
xlim(xmax=3) # adjust the max leaving min unchanged
1542+
xlim(xmin=1) # adjust the min leaving max unchanged
15571543
15581544
Setting limits turns autoscaling off for the x-axis.
15591545
1560-
The new axis limits are returned as a length 2 tuple.
1546+
Returns
1547+
-------
1548+
xmin, xmax
1549+
A tuple of the new x-axis limits.
15611550
1551+
Notes
1552+
-----
1553+
Calling this function with no arguments (e.g. ``xlim()``) is the pyplot
1554+
equivalent of calling `~.Axes.get_xlim` on the current axes.
1555+
Calling this function with arguments is the pyplot equivalent of calling
1556+
`~.Axes.set_xlim` on the current axes. All arguments are passed though.
15621557
"""
15631558
ax = gca()
15641559
if not args and not kwargs:
@@ -1569,23 +1564,33 @@ def xlim(*args, **kwargs):
15691564

15701565
def ylim(*args, **kwargs):
15711566
"""
1572-
Get or set the *y*-limits of the current axes.
1567+
Get or set the y-limits of the current axes.
15731568
1574-
::
1569+
Call signatures::
15751570
1576-
ymin, ymax = ylim() # return the current ylim
1577-
ylim( (ymin, ymax) ) # set the ylim to ymin, ymax
1578-
ylim( ymin, ymax ) # set the ylim to ymin, ymax
1571+
ymin, ymax = ylim() # return the current ylim
1572+
ylim((ymin, ymax)) # set the ylim to ymin, ymax
1573+
ylim(ymin, ymax) # set the ylim to ymin, ymax
15791574
1580-
If you do not specify args, you can pass the *ymin* and *ymax* as
1581-
kwargs, e.g.::
1575+
If you do not specify args, you can alternatively pass *ymin* or *ymax* as
1576+
kwargs, i.e.::
15821577
1583-
ylim(ymax=3) # adjust the max leaving min unchanged
1584-
ylim(ymin=1) # adjust the min leaving max unchanged
1578+
ylim(ymax=3) # adjust the max leaving min unchanged
1579+
ylim(ymin=1) # adjust the min leaving max unchanged
15851580
15861581
Setting limits turns autoscaling off for the y-axis.
15871582
1588-
The new axis limits are returned as a length 2 tuple.
1583+
Returns
1584+
-------
1585+
ymin, ymax
1586+
A tuple of the new y-axis limits.
1587+
1588+
Notes
1589+
-----
1590+
Calling this function with no arguments (e.g. ``ylim()``) is the pyplot
1591+
equivalent of calling `~.Axes.get_ylim` on the current axes.
1592+
Calling this function with arguments is the pyplot equivalent of calling
1593+
`~.Axes.set_ylim` on the current axes. All arguments are passed though.
15891594
"""
15901595
ax = gca()
15911596
if not args and not kwargs:
@@ -1597,13 +1602,23 @@ def ylim(*args, **kwargs):
15971602
@docstring.dedent_interpd
15981603
def xscale(*args, **kwargs):
15991604
"""
1600-
Set the scaling of the *x*-axis.
1605+
Set the scaling of the x-axis.
16011606
1602-
call signature::
1607+
Call signature::
16031608
1604-
xscale(scale, **kwargs)
1609+
xscale(scale, **kwargs)
16051610
1606-
The available scales are: %(scale)s
1611+
Parameters
1612+
----------
1613+
scale : [%(scale)s]
1614+
The scaling type.
1615+
**kwargs
1616+
Additional parameters depend on *scale*. See Notes.
1617+
1618+
Notes
1619+
-----
1620+
This is the pyplot equivalent of calling `~.Axes.set_xscale` on the
1621+
current axes.
16071622
16081623
Different keywords may be accepted, depending on the scale:
16091624
@@ -1615,13 +1630,23 @@ def xscale(*args, **kwargs):
16151630
@docstring.dedent_interpd
16161631
def yscale(*args, **kwargs):
16171632
"""
1618-
Set the scaling of the *y*-axis.
1633+
Set the scaling of the y-axis.
16191634
1620-
call signature::
1635+
Call signature::
1636+
1637+
yscale(scale, **kwargs)
16211638
1622-
yscale(scale, **kwargs)
1639+
Parameters
1640+
----------
1641+
scale : [%(scale)s]
1642+
The scaling type.
1643+
**kwargs
1644+
Additional parameters depend on *scale*. See Notes.
16231645
1624-
The available scales are: %(scale)s
1646+
Notes
1647+
-----
1648+
This is the pyplot equivalent of calling `~.Axes.set_yscale` on the
1649+
current axes.
16251650
16261651
Different keywords may be accepted, depending on the scale:
16271652
@@ -1632,24 +1657,63 @@ def yscale(*args, **kwargs):
16321657

16331658
def xticks(*args, **kwargs):
16341659
"""
1635-
Get or set the *x*-limits of the current tick locations and labels.
1660+
Get or set the current tick locations and labels of the x-axis.
16361661
1637-
::
1662+
Call signatures::
16381663
1639-
# return locs, labels where locs is an array of tick locations and
1640-
# labels is an array of tick labels.
1641-
locs, labels = xticks()
1664+
locs, labels = xticks() # Get locations and labels
16421665
1643-
# set the locations of the xticks
1644-
xticks( arange(6) )
1666+
xticks(locs, [labels], **kwargs) # Set locations and labels
16451667
1646-
# set the locations and labels of the xticks
1647-
xticks( arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue') )
1668+
Parameters
1669+
----------
1670+
locs : array_like
1671+
A list of positions at which ticks should be placed. You can pass an
1672+
empty list to disable xticks.
16481673
1649-
The keyword args, if any, are :class:`~matplotlib.text.Text`
1650-
properties. For example, to rotate long labels::
1674+
labels : array_like, optional
1675+
A list of explicit labels to place at the given *locs*.
16511676
1652-
xticks( arange(12), calendar.month_name[1:13], rotation=17 )
1677+
**kwargs
1678+
:class:`.Text` properties can be used to control the appearance of
1679+
the labels.
1680+
1681+
Returns
1682+
-------
1683+
locs
1684+
An array of label locations.
1685+
labels
1686+
A list of `.Text` objects.
1687+
1688+
Notes
1689+
-----
1690+
Calling this function with no arguments (e.g. ``xticks()``) is the pyplot
1691+
equivalent of calling `~.Axes.get_xticks` and `~.Axes.get_xticklabels` on
1692+
the current axes.
1693+
Calling this function with arguments is the pyplot equivalent of calling
1694+
`~.Axes.set_xticks` and `~.Axes.set_xticklabels` on the current axes.
1695+
1696+
Examples
1697+
--------
1698+
Get the current locations and labels:
1699+
1700+
>>> locs, labels = xticks()
1701+
1702+
Set label locations:
1703+
1704+
>>> xticks(np.arange(0, 1, step=0.2))
1705+
1706+
Set text labels:
1707+
1708+
>>> xticks(np.arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue'))
1709+
1710+
Set text labels and properties:
1711+
1712+
>>> xticks(np.arange(12), calendar.month_name[1:13], rotation=20)
1713+
1714+
Disable xticks:
1715+
1716+
>>> xticks([])
16531717
"""
16541718
ax = gca()
16551719

@@ -1672,24 +1736,63 @@ def xticks(*args, **kwargs):
16721736

16731737
def yticks(*args, **kwargs):
16741738
"""
1675-
Get or set the *y*-limits of the current tick locations and labels.
1739+
Get or set the current tick locations and labels of the y-axis.
1740+
1741+
Call signatures::
1742+
1743+
locs, labels = yticks() # Get locations and labels
1744+
1745+
yticks(locs, [labels], **kwargs) # Set locations and labels
1746+
1747+
Parameters
1748+
----------
1749+
locs : array_like
1750+
A list of positions at which ticks should be placed. You can pass an
1751+
empty list to disable yticks.
1752+
1753+
labels : array_like, optional
1754+
A list of explicit labels to place at the given *locs*.
1755+
1756+
**kwargs
1757+
:class:`.Text` properties can be used to control the appearance of
1758+
the labels.
1759+
1760+
Returns
1761+
-------
1762+
locs
1763+
An array of label locations.
1764+
labels
1765+
A list of `.Text` objects.
1766+
1767+
Notes
1768+
-----
1769+
Calling this function with no arguments (e.g. ``yticks()``) is the pyplot
1770+
equivalent of calling `~.Axes.get_yticks` and `~.Axes.get_yticklabels` on
1771+
the current axes.
1772+
Calling this function with arguments is the pyplot equivalent of calling
1773+
`~.Axes.set_yticks` and `~.Axes.set_yticklabels` on the current axes.
1774+
1775+
Examples
1776+
--------
1777+
Get the current locations and labels:
1778+
1779+
>>> locs, labels = yticks()
1780+
1781+
Set label locations:
1782+
1783+
>>> yticks(np.arange(0, 1, step=0.2))
16761784
1677-
::
1785+
Set text labels:
16781786
1679-
# return locs, labels where locs is an array of tick locations and
1680-
# labels is an array of tick labels.
1681-
locs, labels = yticks()
1787+
>>> yticks(np.arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue'))
16821788
1683-
# set the locations of the yticks
1684-
yticks( arange(6) )
1789+
Set text labels and properties:
16851790
1686-
# set the locations and labels of the yticks
1687-
yticks( arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue') )
1791+
>>> yticks(np.arange(12), calendar.month_name[1:13], rotation=45)
16881792
1689-
The keyword args, if any, are :class:`~matplotlib.text.Text`
1690-
properties. For example, to rotate long labels::
1793+
Disable yticks:
16911794
1692-
yticks( arange(12), calendar.month_name[1:13], rotation=45 )
1795+
>>> yticks([])
16931796
"""
16941797
ax = gca()
16951798

0 commit comments

Comments
 (0)