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

Skip to content

Commit b6cccde

Browse files
committed
improve docstrings of pyplot.xticks and pyplot.yticks
1 parent 407a460 commit b6cccde

File tree

1 file changed

+96
-24
lines changed

1 file changed

+96
-24
lines changed

lib/matplotlib/pyplot.py

Lines changed: 96 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,24 +1632,60 @@ 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.
1647+
1648+
labels : array_like, optional
1649+
A list of explicit labels to place the the given *locs*. You can pass
1650+
an empty list to disable xticks.
1651+
1652+
**kwargs
1653+
:class:`.Text` properties can be used to control the appearence 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+
This is just a convenient shortcut for calling `.get_xticks` and
1666+
`.get_xticklabels` or `.set_xticks` and `.set_xticklabels` on the current
1667+
axes.
1668+
1669+
Examples
1670+
--------
1671+
Get the current locations and labels:
1672+
1673+
>>> locs, labels = xticks()
1674+
1675+
Set label locations:
1676+
1677+
>>> xticks(np.arange(0, 1, step=0.2))
1678+
1679+
Set text labels:
16381680
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()
1681+
>>> xticks(np.arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue'))
16421682
1643-
# set the locations of the xticks
1644-
xticks( arange(6) )
16451683
1646-
# set the locations and labels of the xticks
1647-
xticks( arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue') )
1684+
>>> xticks(np.arange(12), calendar.month_name[1:13], rotation=20)
16481685
1649-
The keyword args, if any, are :class:`~matplotlib.text.Text`
1650-
properties. For example, to rotate long labels::
1686+
Disable xticks:
16511687
1652-
xticks( arange(12), calendar.month_name[1:13], rotation=17 )
1688+
>>> xticks([])
16531689
"""
16541690
ax = gca()
16551691

@@ -1672,24 +1708,60 @@ def xticks(*args, **kwargs):
16721708

16731709
def yticks(*args, **kwargs):
16741710
"""
1675-
Get or set the *y*-limits of the current tick locations and labels.
1711+
Get or set the current tick locations and labels of the y-axis.
16761712
1677-
::
1713+
Call signatures::
1714+
1715+
locs, labels = yticks() # Get locations and labels
1716+
1717+
yticks(locs, [labels], **kwargs) # Set locations and labels
1718+
1719+
Parameters
1720+
----------
1721+
locs : array_like
1722+
A list of positions at which ticks should be placed.
1723+
1724+
labels : array_like, optional
1725+
A list of explicit labels to place the the given *locs*. You can pass
1726+
an empty list to disable yticks.
1727+
1728+
**kwargs
1729+
:class:`.Text` properties can be used to control the appearence of
1730+
the labels.
1731+
1732+
Returns
1733+
-------
1734+
locs
1735+
An array of label locations.
1736+
labels
1737+
A list of `.Text` objects.
1738+
1739+
Notes
1740+
-----
1741+
This is just a convenient shortcut for calling `.get_yticks` and
1742+
`.get_yticklabels` or `.set_yticks` and `.set_yticklabels` on the current
1743+
axes.
1744+
1745+
Examples
1746+
--------
1747+
Get the current locations and labels:
1748+
1749+
>>> locs, labels = yticks()
1750+
1751+
Set label locations:
1752+
1753+
>>> yticks(np.arange(0, 1, step=0.2))
1754+
1755+
Set text labels:
16781756
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()
1757+
>>> yticks(np.arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue'))
16821758
1683-
# set the locations of the yticks
1684-
yticks( arange(6) )
16851759
1686-
# set the locations and labels of the yticks
1687-
yticks( arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue') )
1760+
>>> yticks(np.arange(12), calendar.month_name[1:13], rotation=45)
16881761
1689-
The keyword args, if any, are :class:`~matplotlib.text.Text`
1690-
properties. For example, to rotate long labels::
1762+
Disable yticks:
16911763
1692-
yticks( arange(12), calendar.month_name[1:13], rotation=45 )
1764+
>>> yticks([])
16931765
"""
16941766
ax = gca()
16951767

0 commit comments

Comments
 (0)