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

Skip to content

Commit b150eb5

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

2 files changed

Lines changed: 110 additions & 15 deletions

File tree

lib/matplotlib/axes/_axes.py

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,23 +2396,71 @@ def stem(self, *args, **kwargs):
23962396
23972397
Call signatures::
23982398
2399-
stem(y, linefmt='b-', markerfmt='bo', basefmt='r-')
2400-
stem(x, y, linefmt='b-', markerfmt='bo', basefmt='r-')
2399+
stem(y)
2400+
stem(x, y)
24012401
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*.
2402+
A stem plot plots vertical lines at each *x* location from the baseline
2403+
to *y*, and places a marker there.
24062404
2407-
If no *x* values are provided, the default is (0, 1, ..., len(y) - 1)
24082405
2409-
Return value is a tuple (*markerline*, *stemlines*,
2410-
*baseline*). See :class:`~matplotlib.container.StemContainer`
2406+
Parameters
2407+
----------
2408+
x : array-like, optional
2409+
The x-positions of the stems. Default: (0, 1, ..., len(y) - 1).
2410+
2411+
y : array-like
2412+
The y-values of the stem heads.
2413+
2414+
linefmt : str, optional
2415+
A string defining the properties of the vertical lines. Usually,
2416+
this will be a color or a color and a linestyle:
2417+
2418+
========= =============
2419+
Character Line Style
2420+
========= =============
2421+
``'-'`` solid line
2422+
``'--'`` dashed line
2423+
``'-.'`` dash-dot line
2424+
``':'`` dotted line
2425+
========= =============
2426+
2427+
Default: 'C0-', i.e. solid line with the first color of the color
2428+
cycle.
2429+
2430+
Note: While it is technically possible to specify valid formats
2431+
other than color or color and linestyle (e.g. 'rx' or '-.'), this
2432+
is beyond the intention of the method and will most likely not
2433+
result in a reasonable reasonable plot.
2434+
2435+
markerfmt : str, optional
2436+
A string defining the properties of the markers at the stem heads.
2437+
Default: 'C0o', i.e. filled circles with the first color of the
2438+
color cycle.
2439+
2440+
basefmt : str, optional
2441+
A format string defining the properties of the baseline.
2442+
2443+
Default: 'C3-' ('C2-' in classic mode).
2444+
2445+
bottom : float, optional, default: 0
2446+
The y-position of the baseline.
2447+
2448+
label : str, optional, default: None
2449+
The label to use for the stems in legends.
2450+
2451+
2452+
Returns
2453+
-------
2454+
a :class:`~matplotlib.container.StemContainer`
2455+
2456+
The stemcontainer may be treated like a tuple
2457+
(*markerline*, *stemlines*, *baseline*)
2458+
24112459
24122460
.. seealso::
2413-
This
2414-
`document <http://www.mathworks.com/help/techdoc/ref/stem.html>`_
2415-
for details.
2461+
The MATLAB function
2462+
`stem <http://www.mathworks.com/help/techdoc/ref/stem.html>`_
2463+
which inspired this method.
24162464
24172465
"""
24182466
remember_hold = self._hold

lib/matplotlib/container.py

Lines changed: 50 additions & 3 deletions
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)