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

Skip to content

Commit f4127b1

Browse files
authored
Merge pull request #11542 from fredrik-1/doc_thetagrids
Documentation polar grids
2 parents 5a22c8b + 5ab478a commit f4127b1

File tree

2 files changed

+138
-82
lines changed

2 files changed

+138
-82
lines changed

lib/matplotlib/projections/polar.py

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,27 +1221,39 @@ def set_rscale(self, *args, **kwargs):
12211221
def set_rticks(self, *args, **kwargs):
12221222
return Axes.set_yticks(self, *args, **kwargs)
12231223

1224-
@docstring.dedent_interpd
12251224
def set_thetagrids(self, angles, labels=None, fmt=None, **kwargs):
12261225
"""
1227-
Set the angles at which to place the theta grids (these
1228-
gridlines are equal along the theta dimension). *angles* is in
1229-
degrees.
1226+
Set the theta gridlines in a polar plot.
12301227
1231-
*labels*, if not None, is a ``len(angles)`` list of strings of
1232-
the labels to use at each angle.
1233-
1234-
If *labels* is None, the labels will be ``fmt %% angle``
1235-
1236-
Return value is a list of tuples (*line*, *label*), where
1237-
*line* is :class:`~matplotlib.lines.Line2D` instances and the
1238-
*label* is :class:`~matplotlib.text.Text` instances.
1228+
Parameters
1229+
----------
1230+
angles : tuple with floats, degrees
1231+
The angles of the theta gridlines.
12391232
1240-
kwargs are optional text properties for the labels:
1233+
labels : tuple with strings or None
1234+
The labels to use at each theta gridline. The
1235+
`.projections.polar.ThetaFormatter` will be used if None.
12411236
1242-
%(Text)s
1237+
fmt : str or None
1238+
Format string used in `matplotlib.ticker.FormatStrFormatter`.
1239+
For example '%f'. Note that the angle that is used is in
1240+
radians.
12431241
1244-
ACCEPTS: sequence of floats
1242+
Returns
1243+
-------
1244+
lines, labels : list of `.lines.Line2D`, list of `.text.Text`
1245+
*lines* are the theta gridlines and *labels* are the tick labels.
1246+
1247+
Other Parameters
1248+
----------------
1249+
**kwargs
1250+
*kwargs* are optional `~.Text` properties for the labels.
1251+
1252+
See Also
1253+
--------
1254+
.PolarAxes.set_rgrids
1255+
.Axis.get_gridlines
1256+
.Axis.get_ticklabels
12451257
"""
12461258

12471259
# Make sure we take into account unitized data
@@ -1256,29 +1268,42 @@ def set_thetagrids(self, angles, labels=None, fmt=None, **kwargs):
12561268
t.update(kwargs)
12571269
return self.xaxis.get_ticklines(), self.xaxis.get_ticklabels()
12581270

1259-
@docstring.dedent_interpd
12601271
def set_rgrids(self, radii, labels=None, angle=None, fmt=None,
12611272
**kwargs):
12621273
"""
1263-
Set the radial locations and labels of the *r* grids.
1264-
1265-
The labels will appear at radial distances *radii* at the
1266-
given *angle* in degrees.
1274+
Set the radial gridlines on a polar plot.
12671275
1268-
*labels*, if not None, is a ``len(radii)`` list of strings of the
1269-
labels to use at each radius.
1270-
1271-
If *labels* is None, the built-in formatter will be used.
1276+
Parameters
1277+
----------
1278+
radii : tuple with floats
1279+
The radii for the radial gridlines
12721280
1273-
Return value is a list of tuples (*line*, *label*), where
1274-
*line* is :class:`~matplotlib.lines.Line2D` instances and the
1275-
*label* is :class:`~matplotlib.text.Text` instances.
1281+
labels : tuple with strings or None
1282+
The labels to use at each radial gridline. The
1283+
`matplotlib.ticker.ScalarFormatter` will be used if None.
12761284
1277-
kwargs are optional text properties for the labels:
1285+
angle : float
1286+
The angular position of the radius labels in degrees.
12781287
1279-
%(Text)s
1288+
fmt : str or None
1289+
Format string used in `matplotlib.ticker.FormatStrFormatter`.
1290+
For example '%f'.
12801291
1281-
ACCEPTS: sequence of floats
1292+
Returns
1293+
-------
1294+
lines, labels : list of `.lines.Line2D`, list of `.text.Text`
1295+
*lines* are the radial gridlines and *labels* are the tick labels.
1296+
1297+
Other Parameters
1298+
----------------
1299+
**kwargs
1300+
*kwargs* are optional `~.Text` properties for the labels.
1301+
1302+
See Also
1303+
--------
1304+
.PolarAxes.set_thetagrids
1305+
.Axis.get_gridlines
1306+
.Axis.get_ticklabels
12821307
"""
12831308
# Make sure we take into account unitized data
12841309
radii = self.convert_xunits(radii)

lib/matplotlib/pyplot.py

Lines changed: 83 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,36 +1626,62 @@ def yticks(ticks=None, labels=None, **kwargs):
16261626

16271627
return locs, silent_list('Text yticklabel', labels)
16281628

1629-
16301629
def rgrids(*args, **kwargs):
16311630
"""
1632-
Get or set the radial gridlines on a polar plot.
1631+
Get or set the radial gridlines on the current polar plot.
1632+
1633+
Call signatures::
16331634
1634-
call signatures::
1635+
lines, labels = rgrids()
1636+
lines, labels = rgrids(radii, labels=None, angle=22.5, fmt=None, **kwargs)
16351637
1636-
lines, labels = rgrids()
1637-
lines, labels = rgrids(radii, labels=None, angle=22.5, **kwargs)
1638+
When called with no arguments, `.rgrids` simply returns the tuple
1639+
(*lines*, *labels*). When called with arguments, the labels will
1640+
appear at the specified radial distances and angle.
16381641
1639-
When called with no arguments, :func:`rgrid` simply returns the
1640-
tuple (*lines*, *labels*), where *lines* is an array of radial
1641-
gridlines (:class:`~matplotlib.lines.Line2D` instances) and
1642-
*labels* is an array of tick labels
1643-
(:class:`~matplotlib.text.Text` instances). When called with
1644-
arguments, the labels will appear at the specified radial
1645-
distances and angles.
1642+
Parameters
1643+
----------
1644+
radii : tuple with floats
1645+
The radii for the radial gridlines
16461646
1647-
*labels*, if not *None*, is a len(*radii*) list of strings of the
1648-
labels to use at each angle.
1647+
labels : tuple with strings or None
1648+
The labels to use at each radial gridline. The
1649+
`matplotlib.ticker.ScalarFormatter` will be used if None.
16491650
1650-
If *labels* is None, the rformatter will be used
1651+
angle : float
1652+
The angular position of the radius labels in degrees.
16511653
1652-
Examples::
1654+
fmt : str or None
1655+
Format string used in `matplotlib.ticker.FormatStrFormatter`.
1656+
For example '%f'.
16531657
1654-
# set the locations of the radial gridlines and labels
1658+
Returns
1659+
-------
1660+
lines, labels : list of `.lines.Line2D`, list of `.text.Text`
1661+
*lines* are the radial gridlines and *labels* are the tick labels.
1662+
1663+
Other Parameters
1664+
----------------
1665+
**kwargs
1666+
*kwargs* are optional `~.Text` properties for the labels.
1667+
1668+
Examples
1669+
--------
1670+
::
1671+
1672+
# set the locations of the radial gridlines
16551673
lines, labels = rgrids( (0.25, 0.5, 1.0) )
16561674
1657-
# set the locations and labels of the radial gridlines and labels
1658-
lines, labels = rgrids( (0.25, 0.5, 1.0), ('Tom', 'Dick', 'Harry' )
1675+
# set the locations and labels of the radial gridlines
1676+
lines, labels = rgrids( (0.25, 0.5, 1.0), ('Tom', 'Dick', 'Harry' ))
1677+
1678+
See Also
1679+
--------
1680+
.pyplot.thetagrids
1681+
.projections.polar.PolarAxes.set_rgrids
1682+
.Axis.get_gridlines
1683+
.Axis.get_ticklabels
1684+
16591685
16601686
"""
16611687
ax = gca()
@@ -1670,57 +1696,62 @@ def rgrids(*args, **kwargs):
16701696
return ( silent_list('Line2D rgridline', lines),
16711697
silent_list('Text rgridlabel', labels) )
16721698

1673-
16741699
def thetagrids(*args, **kwargs):
16751700
"""
1676-
Get or set the theta locations of the gridlines in a polar plot.
1701+
Get or set the theta gridlines on the current polar plot.
16771702
1678-
If no arguments are passed, return a tuple (*lines*, *labels*)
1679-
where *lines* is an array of radial gridlines
1680-
(:class:`~matplotlib.lines.Line2D` instances) and *labels* is an
1681-
array of tick labels (:class:`~matplotlib.text.Text` instances)::
1682-
1683-
lines, labels = thetagrids()
1684-
1685-
Otherwise the syntax is::
1686-
1687-
lines, labels = thetagrids(angles, labels=None, fmt='%d', frac = 1.1)
1688-
1689-
set the angles at which to place the theta grids (these gridlines
1690-
are equal along the theta dimension).
1691-
1692-
*angles* is in degrees.
1703+
Call signatures::
16931704
1694-
*labels*, if not *None*, is a len(angles) list of strings of the
1695-
labels to use at each angle.
1705+
lines, labels = thetagrids()
1706+
lines, labels = thetagrids(angles, labels=None, fmt=None, **kwargs)
16961707
1697-
If *labels* is *None*, the labels will be ``fmt%angle``.
1708+
When called with no arguments, `.thetagrids` simply returns the tuple
1709+
(*lines*, *labels*). When called with arguments, the labels will
1710+
appear at the specified angles.
16981711
1699-
*frac* is the fraction of the polar axes radius at which to place
1700-
the label (1 is the edge). e.g., 1.05 is outside the axes and 0.95
1701-
is inside the axes.
1712+
Parameters
1713+
----------
1714+
angles : tuple with floats, degrees
1715+
The angles of the theta gridlines.
17021716
1703-
Return value is a list of tuples (*lines*, *labels*):
1717+
labels : tuple with strings or None
1718+
The labels to use at each radial gridline. The
1719+
`.projections.polar.ThetaFormatter` will be used if None.
17041720
1705-
- *lines* are :class:`~matplotlib.lines.Line2D` instances
1721+
fmt : str or None
1722+
Format string used in `matplotlib.ticker.FormatStrFormatter`.
1723+
For example '%f'. Note that the angle in radians will be used.
17061724
1707-
- *labels* are :class:`~matplotlib.text.Text` instances.
1725+
Returns
1726+
-------
1727+
lines, labels : list of `.lines.Line2D`, list of `.text.Text`
1728+
*lines* are the theta gridlines and *labels* are the tick labels.
17081729
1709-
Note that on input, the *labels* argument is a list of strings,
1710-
and on output it is a list of :class:`~matplotlib.text.Text`
1711-
instances.
1730+
Other Parameters
1731+
----------------
1732+
**kwargs
1733+
*kwargs* are optional `~.Text` properties for the labels.
17121734
1713-
Examples::
1735+
Examples
1736+
--------
1737+
::
17141738
1715-
# set the locations of the radial gridlines and labels
1739+
# set the locations of the angular gridlines
17161740
lines, labels = thetagrids( range(45,360,90) )
17171741
1718-
# set the locations and labels of the radial gridlines and labels
1742+
# set the locations and labels of the angular gridlines
17191743
lines, labels = thetagrids( range(45,360,90), ('NE', 'NW', 'SW','SE') )
1744+
1745+
See Also
1746+
--------
1747+
.pyplot.rgrids
1748+
.projections.polar.PolarAxes.set_thetagrids
1749+
.Axis.get_gridlines
1750+
.Axis.get_ticklabels
17201751
"""
17211752
ax = gca()
17221753
if not isinstance(ax, PolarAxes):
1723-
raise RuntimeError('rgrids only defined for polar axes')
1754+
raise RuntimeError('thetagrids only defined for polar axes')
17241755
if len(args)==0:
17251756
lines = ax.xaxis.get_ticklines()
17261757
labels = ax.xaxis.get_ticklabels()

0 commit comments

Comments
 (0)