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

Skip to content

Commit fc775f5

Browse files
committed
improve docstrings of pyplot.xticks and pyplot.yticks
1 parent 72770e6 commit fc775f5

File tree

1 file changed

+102
-24
lines changed

1 file changed

+102
-24
lines changed

lib/matplotlib/pyplot.py

Lines changed: 102 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,24 +1632,63 @@ def yscale(*args, **kwargs):
16321632

16331633
def xticks(*args, **kwargs):
16341634
"""
1635-
Get or set the *x*-limits of the current tick locations and labels.
1635+
Get or set the current tick locations and labels of the x-axis.
16361636
1637-
::
1637+
Call signatures::
1638+
1639+
locs, labels = xticks() # Get locations and labels
1640+
1641+
xticks(locs, [labels], **kwargs) # Set locations and labels
1642+
1643+
Parameters
1644+
----------
1645+
locs : array_like
1646+
A list of positions at which ticks should be placed. You can pass an
1647+
empty list to disable xticks.
1648+
1649+
labels : array_like, optional
1650+
A list of explicit labels to place at the given *locs*.
1651+
1652+
**kwargs
1653+
:class:`.Text` properties can be used to control the appearance of
1654+
the labels.
1655+
1656+
Returns
1657+
-------
1658+
locs
1659+
An array of label locations.
1660+
labels
1661+
A list of `.Text` objects.
1662+
1663+
Notes
1664+
-----
1665+
Calling this function with no arguments (e.g. ``xticks()``) is the pyplot
1666+
equivalent of calling `~.Axes.get_xticks` and `~.Axes.get_xticklabels` on
1667+
the current axes.
1668+
Calling this function with arguments is the pyplot equivalent of calling
1669+
`~.Axes.set_xticks` and `~.Axes.set_xticklabels` on the current axes.
1670+
1671+
Examples
1672+
--------
1673+
Get the current locations and labels:
1674+
1675+
>>> locs, labels = xticks()
1676+
1677+
Set label locations:
1678+
1679+
>>> xticks(np.arange(0, 1, step=0.2))
1680+
1681+
Set text labels:
16381682
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()
1683+
>>> xticks(np.arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue'))
16421684
1643-
# set the locations of the xticks
1644-
xticks( arange(6) )
1685+
Set text labels and properties:
16451686
1646-
# set the locations and labels of the xticks
1647-
xticks( arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue') )
1687+
>>> xticks(np.arange(12), calendar.month_name[1:13], rotation=20)
16481688
1649-
The keyword args, if any, are :class:`~matplotlib.text.Text`
1650-
properties. For example, to rotate long labels::
1689+
Disable xticks:
16511690
1652-
xticks( arange(12), calendar.month_name[1:13], rotation=17 )
1691+
>>> xticks([])
16531692
"""
16541693
ax = gca()
16551694

@@ -1672,24 +1711,63 @@ def xticks(*args, **kwargs):
16721711

16731712
def yticks(*args, **kwargs):
16741713
"""
1675-
Get or set the *y*-limits of the current tick locations and labels.
1714+
Get or set the current tick locations and labels of the y-axis.
16761715
1677-
::
1716+
Call signatures::
1717+
1718+
locs, labels = yticks() # Get locations and labels
1719+
1720+
yticks(locs, [labels], **kwargs) # Set locations and labels
1721+
1722+
Parameters
1723+
----------
1724+
locs : array_like
1725+
A list of positions at which ticks should be placed. You can pass an
1726+
empty list to disable yticks.
1727+
1728+
labels : array_like, optional
1729+
A list of explicit labels to place at the given *locs*.
1730+
1731+
**kwargs
1732+
:class:`.Text` properties can be used to control the appearance of
1733+
the labels.
1734+
1735+
Returns
1736+
-------
1737+
locs
1738+
An array of label locations.
1739+
labels
1740+
A list of `.Text` objects.
1741+
1742+
Notes
1743+
-----
1744+
Calling this function with no arguments (e.g. ``yticks()``) is the pyplot
1745+
equivalent of calling `~.Axes.get_yticks` and `~.Axes.get_yticklabels` on
1746+
the current axes.
1747+
Calling this function with arguments is the pyplot equivalent of calling
1748+
`~.Axes.set_yticks` and `~.Axes.set_yticklabels` on the current axes.
1749+
1750+
Examples
1751+
--------
1752+
Get the current locations and labels:
1753+
1754+
>>> locs, labels = yticks()
1755+
1756+
Set label locations:
1757+
1758+
>>> yticks(np.arange(0, 1, step=0.2))
1759+
1760+
Set text labels:
16781761
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()
1762+
>>> yticks(np.arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue'))
16821763
1683-
# set the locations of the yticks
1684-
yticks( arange(6) )
1764+
Set text labels and properties:
16851765
1686-
# set the locations and labels of the yticks
1687-
yticks( arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue') )
1766+
>>> yticks(np.arange(12), calendar.month_name[1:13], rotation=45)
16881767
1689-
The keyword args, if any, are :class:`~matplotlib.text.Text`
1690-
properties. For example, to rotate long labels::
1768+
Disable yticks:
16911769
1692-
yticks( arange(12), calendar.month_name[1:13], rotation=45 )
1770+
>>> yticks([])
16931771
"""
16941772
ax = gca()
16951773

0 commit comments

Comments
 (0)