Skip to content

Commit d7be98f

Browse files
committed
improve Axes.stem docstring
1 parent 37978a8 commit d7be98f

File tree

2 files changed

+113
-15
lines changed

2 files changed

+113
-15
lines changed

lib/matplotlib/axes/_axes.py

+63-12
Original file line numberDiff line numberDiff line change
@@ -2392,27 +2392,78 @@ def broken_barh(self, xranges, yrange, **kwargs):
23922392
@_preprocess_data(replace_all_args=True, label_namer=None)
23932393
def stem(self, *args, **kwargs):
23942394
"""
2395+
stem(*args, linefmt=None, markerfmt=None, basefmt=None, data=None,
2396+
bottom=0, label=None)
2397+
23952398
Create a stem plot.
23962399
23972400
Call signatures::
23982401
2399-
stem(y, linefmt='b-', markerfmt='bo', basefmt='r-')
2400-
stem(x, y, linefmt='b-', markerfmt='bo', basefmt='r-')
2402+
stem(y)
2403+
stem(x, y)
2404+
2405+
A stem plot plots vertical lines at each *x* location from the baseline
2406+
to *y*, and places a marker there.
2407+
2408+
2409+
Parameters
2410+
----------
2411+
x : array-like, optional
2412+
The x-positions of the stems. Default: (0, 1, ..., len(y) - 1).
2413+
2414+
y : array-like
2415+
The y-values of the stem heads.
2416+
2417+
linefmt : str, optional
2418+
A string defining the properties of the vertical lines. Usually,
2419+
this will be a color or a color and a linestyle:
2420+
2421+
========= =============
2422+
Character Line Style
2423+
========= =============
2424+
``'-'`` solid line
2425+
``'--'`` dashed line
2426+
``'-.'`` dash-dot line
2427+
``':'`` dotted line
2428+
========= =============
2429+
2430+
Default: 'C0-', i.e. solid line with the first color of the color
2431+
cycle.
24012432
2402-
A stem plot plots vertical lines (using *linefmt*) at each *x*
2403-
location from the baseline to *y*, and places a marker there
2404-
using *markerfmt*. A horizontal line at 0 is plotted using
2405-
*basefmt*.
2433+
Note: While it is technically possible to specify valid formats
2434+
other than color or color and linestyle (e.g. 'rx' or '-.'), this
2435+
is beyond the intention of the method and will most likely not
2436+
result in a reasonable reasonable plot.
2437+
2438+
markerfmt : str, optional
2439+
A string defining the properties of the markers at the stem heads.
2440+
Default: 'C0o', i.e. filled circles with the first color of the
2441+
color cycle.
2442+
2443+
basefmt : str, optional
2444+
A format string defining the properties of the baseline.
2445+
2446+
Default: 'C3-' ('C2-' in classic mode).
2447+
2448+
bottom : float, optional, default: 0
2449+
The y-position of the baseline.
2450+
2451+
label : str, optional, default: None
2452+
The label to use for the stems in legends.
2453+
2454+
2455+
Returns
2456+
-------
2457+
a :class:`~matplotlib.container.StemContainer`
24062458
2407-
If no *x* values are provided, the default is (0, 1, ..., len(y) - 1)
2459+
The stemcontainer may be treated like a tuple
2460+
(*markerline*, *stemlines*, *baseline*)
24082461
2409-
Return value is a tuple (*markerline*, *stemlines*,
2410-
*baseline*). See :class:`~matplotlib.container.StemContainer`
24112462
24122463
.. seealso::
2413-
This
2414-
`document <http://www.mathworks.com/help/techdoc/ref/stem.html>`_
2415-
for details.
2464+
The MATLAB function
2465+
`stem <http://www.mathworks.com/help/techdoc/ref/stem.html>`_
2466+
which inspired this method.
24162467
24172468
"""
24182469
remember_hold = self._hold

lib/matplotlib/container.py

+50-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
class Container(tuple):
1111
"""
1212
Base class for containers.
13+
14+
Containers are classes that collect semantically related Artists such as
15+
the bars of a bar plot.
1316
"""
1417

1518
def __repr__(self):
@@ -107,6 +110,25 @@ def get_children(self):
107110

108111

109112
class BarContainer(Container):
113+
"""
114+
Container for the artists of bar plots.
115+
116+
E.g. created in a :meth:`.Axes.bar` plot.
117+
118+
The container can be treated as a tuple of the *patches* themselves.
119+
Additionally, you can access these and further parameters by the
120+
attributes.
121+
122+
Attributes
123+
----------
124+
patches : list of :class:`~matplotlib.patches.Rectangle`
125+
The artists of the bars.
126+
127+
errorbar : None or :class:`~matplotlib.container.ErrorbarContainer`
128+
A container for the error bar artists if error bars are present.
129+
*None* otherwise.
130+
131+
"""
110132

111133
def __init__(self, patches, errorbar=None, **kwargs):
112134
self.patches = patches
@@ -115,8 +137,14 @@ def __init__(self, patches, errorbar=None, **kwargs):
115137

116138

117139
class ErrorbarContainer(Container):
118-
'''
119-
Container for errobars.
140+
"""
141+
Container for the artists of error bars.
142+
143+
E.g. created in a :meth:`.Axes.errorbar` plot.
144+
145+
The container can be treated as the *lines* tuple itself.
146+
Additionally, you can access these and further parameters by the
147+
attributes.
120148
121149
Attributes
122150
----------
@@ -132,7 +160,8 @@ class ErrorbarContainer(Container):
132160
133161
has_xerr, has_yerr : bool
134162
``True`` if the errorbar has x/y errors.
135-
'''
163+
164+
"""
136165

137166
def __init__(self, lines, has_xerr=False, has_yerr=False, **kwargs):
138167
self.lines = lines
@@ -142,6 +171,24 @@ def __init__(self, lines, has_xerr=False, has_yerr=False, **kwargs):
142171

143172

144173
class StemContainer(Container):
174+
"""
175+
Container for the artists created in a :meth:`.Axes.stem` plot.
176+
177+
The container can be treated like a namedtuple ``(markerline, stemlines,
178+
baseline)``.
179+
180+
Attributes
181+
----------
182+
markerline : :class:`~matplotlib.lines.Line2D`
183+
The artist of the markers at the stem heads.
184+
185+
stemlines : list of :class:`~matplotlib.lines.Line2D`
186+
The artists of the vertical lines for all stems.
187+
188+
baseline : :class:`~matplotlib.lines.Line2D`
189+
The artist of the horizontal baseline.
190+
191+
"""
145192

146193
def __init__(self, markerline_stemlines_baseline, **kwargs):
147194
markerline, stemlines, baseline = markerline_stemlines_baseline

0 commit comments

Comments
 (0)