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

Appearance settings

Commit cc7d086

Browse filesBrowse files
authored
Merge pull request #10296 from timhoffm/pyplot-doc-xysettings
DOC: Improve docstrings of pyplot axis-related functions
2 parents 2653ce8 + 6f28a57 commit cc7d086
Copy full SHA for cc7d086

File tree

Expand file treeCollapse file tree

2 files changed

+190
-85
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+190
-85
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+12-10Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,19 +200,20 @@ def get_xlabel(self):
200200

201201
def set_xlabel(self, xlabel, fontdict=None, labelpad=None, **kwargs):
202202
"""
203-
Set the label for the xaxis.
203+
Set the label for the x-axis.
204204
205205
Parameters
206206
----------
207-
xlabel : string
208-
x label
207+
xlabel : str
208+
The label text.
209209
210210
labelpad : scalar, optional, default: None
211-
spacing in points between the label and the x-axis
211+
Spacing in points between the label and the x-axis.
212212
213213
Other Parameters
214214
----------------
215-
**kwargs : `~matplotlib.text.Text` properties
215+
**kwargs : `.Text` properties
216+
`.Text` properties control the appearance of the label.
216217
217218
See also
218219
--------
@@ -231,19 +232,20 @@ def get_ylabel(self):
231232

232233
def set_ylabel(self, ylabel, fontdict=None, labelpad=None, **kwargs):
233234
"""
234-
Set the label for the yaxis
235+
Set the label for the y-axis.
235236
236237
Parameters
237238
----------
238-
ylabel : string
239-
y label
239+
ylabel : str
240+
The label text.
240241
241242
labelpad : scalar, optional, default: None
242-
spacing in points between the label and the y-axis
243+
Spacing in points between the label and the y-axis.
243244
244245
Other Parameters
245246
----------------
246-
**kwargs : `~matplotlib.text.Text` properties
247+
**kwargs : `.Text` properties
248+
`.Text` properties control the appearance of the label.
247249
248250
See also
249251
--------

‎lib/matplotlib/pyplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/pyplot.py
+178-75Lines changed: 178 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,65 +1497,60 @@ def axis(*v, **kwargs):
14971497

14981498
def xlabel(s, *args, **kwargs):
14991499
"""
1500-
Set the *x* axis label of the current axis.
1500+
Set the x-axis label of the current axes.
15011501
1502-
Default override is::
1503-
1504-
override = {
1505-
'fontsize' : 'small',
1506-
'verticalalignment' : 'top',
1507-
'horizontalalignment' : 'center'
1508-
}
1502+
Call signature::
15091503
1510-
.. seealso::
1504+
xlabel(label, fontdict=None, labelpad=None, **kwargs)
15111505
1512-
:func:`~matplotlib.pyplot.text`
1513-
For information on how override and the optional args work
1506+
This is the pyplot equivalent of calling `.set_xlabel` on the current axes.
1507+
See there for a full parameter description.
15141508
"""
15151509
return gca().set_xlabel(s, *args, **kwargs)
15161510

15171511

15181512
def ylabel(s, *args, **kwargs):
15191513
"""
1520-
Set the *y* axis label of the current axis.
1514+
Set the y-axis label of the current axes.
15211515
1522-
Defaults override is::
1523-
1524-
override = {
1525-
'fontsize' : 'small',
1526-
'verticalalignment' : 'center',
1527-
'horizontalalignment' : 'right',
1528-
'rotation'='vertical' : }
1516+
Call signature::
15291517
1530-
.. seealso::
1518+
ylabel(label, fontdict=None, labelpad=None, **kwargs)
15311519
1532-
:func:`~matplotlib.pyplot.text`
1533-
For information on how override and the optional args
1534-
work.
1520+
This is the pyplot equivalent of calling `.set_ylabel` on the current axes.
1521+
See there for a full parameter description.
15351522
"""
15361523
return gca().set_ylabel(s, *args, **kwargs)
15371524

15381525

15391526
def xlim(*args, **kwargs):
15401527
"""
1541-
Get or set the *x* limits of the current axes.
1528+
Get or set the x limits of the current axes.
15421529
1543-
::
1530+
Call signatures::
15441531
1545-
xmin, xmax = xlim() # return the current xlim
1546-
xlim( (xmin, xmax) ) # set the xlim to xmin, xmax
1547-
xlim( xmin, xmax ) # set the xlim to xmin, xmax
1532+
xmin, xmax = xlim() # return the current xlim
1533+
xlim((xmin, xmax)) # set the xlim to xmin, xmax
1534+
xlim(xmin, xmax) # set the xlim to xmin, xmax
15481535
1549-
If you do not specify args, you can pass the xmin and xmax as
1550-
kwargs, e.g.::
1536+
If you do not specify args, you can pass *xmin* or *xmax* as kwargs, i.e.::
15511537
1552-
xlim(xmax=3) # adjust the max leaving min unchanged
1553-
xlim(xmin=1) # adjust the min leaving max unchanged
1538+
xlim(xmax=3) # adjust the max leaving min unchanged
1539+
xlim(xmin=1) # adjust the min leaving max unchanged
15541540
15551541
Setting limits turns autoscaling off for the x-axis.
15561542
1557-
The new axis limits are returned as a length 2 tuple.
1543+
Returns
1544+
-------
1545+
xmin, xmax
1546+
A tuple of the new x-axis limits.
15581547
1548+
Notes
1549+
-----
1550+
Calling this function with no arguments (e.g. ``xlim()``) is the pyplot
1551+
equivalent of calling `~.Axes.get_xlim` on the current axes.
1552+
Calling this function with arguments is the pyplot equivalent of calling
1553+
`~.Axes.set_xlim` on the current axes. All arguments are passed though.
15591554
"""
15601555
ax = gca()
15611556
if not args and not kwargs:
@@ -1566,23 +1561,33 @@ def xlim(*args, **kwargs):
15661561

15671562
def ylim(*args, **kwargs):
15681563
"""
1569-
Get or set the *y*-limits of the current axes.
1564+
Get or set the y-limits of the current axes.
15701565
1571-
::
1566+
Call signatures::
15721567
1573-
ymin, ymax = ylim() # return the current ylim
1574-
ylim( (ymin, ymax) ) # set the ylim to ymin, ymax
1575-
ylim( ymin, ymax ) # set the ylim to ymin, ymax
1568+
ymin, ymax = ylim() # return the current ylim
1569+
ylim((ymin, ymax)) # set the ylim to ymin, ymax
1570+
ylim(ymin, ymax) # set the ylim to ymin, ymax
15761571
1577-
If you do not specify args, you can pass the *ymin* and *ymax* as
1578-
kwargs, e.g.::
1572+
If you do not specify args, you can alternatively pass *ymin* or *ymax* as
1573+
kwargs, i.e.::
15791574
1580-
ylim(ymax=3) # adjust the max leaving min unchanged
1581-
ylim(ymin=1) # adjust the min leaving max unchanged
1575+
ylim(ymax=3) # adjust the max leaving min unchanged
1576+
ylim(ymin=1) # adjust the min leaving max unchanged
15821577
15831578
Setting limits turns autoscaling off for the y-axis.
15841579
1585-
The new axis limits are returned as a length 2 tuple.
1580+
Returns
1581+
-------
1582+
ymin, ymax
1583+
A tuple of the new y-axis limits.
1584+
1585+
Notes
1586+
-----
1587+
Calling this function with no arguments (e.g. ``ylim()``) is the pyplot
1588+
equivalent of calling `~.Axes.get_ylim` on the current axes.
1589+
Calling this function with arguments is the pyplot equivalent of calling
1590+
`~.Axes.set_ylim` on the current axes. All arguments are passed though.
15861591
"""
15871592
ax = gca()
15881593
if not args and not kwargs:
@@ -1594,13 +1599,23 @@ def ylim(*args, **kwargs):
15941599
@docstring.dedent_interpd
15951600
def xscale(*args, **kwargs):
15961601
"""
1597-
Set the scaling of the *x*-axis.
1602+
Set the scaling of the x-axis.
15981603
1599-
call signature::
1604+
Call signature::
16001605
1601-
xscale(scale, **kwargs)
1606+
xscale(scale, **kwargs)
16021607
1603-
The available scales are: %(scale)s
1608+
Parameters
1609+
----------
1610+
scale : [%(scale)s]
1611+
The scaling type.
1612+
**kwargs
1613+
Additional parameters depend on *scale*. See Notes.
1614+
1615+
Notes
1616+
-----
1617+
This is the pyplot equivalent of calling `~.Axes.set_xscale` on the
1618+
current axes.
16041619
16051620
Different keywords may be accepted, depending on the scale:
16061621
@@ -1612,13 +1627,23 @@ def xscale(*args, **kwargs):
16121627
@docstring.dedent_interpd
16131628
def yscale(*args, **kwargs):
16141629
"""
1615-
Set the scaling of the *y*-axis.
1630+
Set the scaling of the y-axis.
16161631
1617-
call signature::
1632+
Call signature::
1633+
1634+
yscale(scale, **kwargs)
16181635
1619-
yscale(scale, **kwargs)
1636+
Parameters
1637+
----------
1638+
scale : [%(scale)s]
1639+
The scaling type.
1640+
**kwargs
1641+
Additional parameters depend on *scale*. See Notes.
16201642
1621-
The available scales are: %(scale)s
1643+
Notes
1644+
-----
1645+
This is the pyplot equivalent of calling `~.Axes.set_yscale` on the
1646+
current axes.
16221647
16231648
Different keywords may be accepted, depending on the scale:
16241649
@@ -1629,24 +1654,63 @@ def yscale(*args, **kwargs):
16291654

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

@@ -1669,24 +1733,63 @@ def xticks(*args, **kwargs):
16691733

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.