8000 Make Axes.stem take at least one argument. · matplotlib/matplotlib@eb953ba · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit eb953ba

Browse files
committed
Make Axes.stem take at least one argument.
When it takes only one, the abscissae default to np.arange(len(y))
1 parent 3156405 commit eb953ba

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

lib/matplotlib/axes.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5074,20 +5074,22 @@ def broken_barh(self, xranges, yrange, **kwargs):
50745074

50755075
return col
50765076

5077-
def stem(self, x, y, linefmt='b-', markerfmt='bo', basefmt='r-',
5078-
bottom=None, label=None):
5077+
def stem(self, *args, **kwargs):
50795078
"""
50805079
Create a stem plot.
50815080
5082-
Call signature::
5081+
Call signatures::
50835082
5083+
stem(y, linefmt='b-', markerfmt='bo', basefmt='r-')
50845084
stem(x, y, linefmt='b-', markerfmt='bo', basefmt='r-')
50855085
50865086
A stem plot plots vertical lines (using *linefmt*) at each *x*
50875087
location from the baseline to *y*, and places a marker there
50885088
using *markerfmt*. A horizontal line at 0 is is plotted using
50895089
*basefmt*.
50905090
5091+
If no *x* values are provided, the default is (0, 1, ..., len(y) - 1)
5092+
50915093
Return value is a tuple (*markerline*, *stemlines*,
50925094
*baseline*).
50935095
@@ -5104,6 +5106,25 @@ def stem(self, x, y, linefmt='b-', markerfmt='bo', basefmt='r-',
51045106
if not self._hold: self.cla()
51055107
self.hold(True)
51065108

5109+
# Assume there's at least one data array
5110+
y = np.asarray(args[0], dtype=np.float)
5111+
5112+
# Try a second one
5113+
try:
5114+
second = np.asarray(args[1], dtype=np.float)
5115+
x, y = y, second
5116+
except:
5117+
# The second array doesn't make sense, or it doesn't exist
5118+
second = np.arange(len(y))
5119+
x = second
5120+
5121+
# Popping some defaults
5122+
linefmt = kwargs.pop('linefmt', 'b-')
5123+
markerfmt = kwargs.pop('markerfmt', 'bo')
5124+
basefmt = kwargs.pop('basefmt', 'r-')
5125+
bottom = kwargs.pop('bottom', None)
5126+
label = kwargs.pop('label', None)
5127+
51075128
markerline, = self.plot(x, y, markerfmt, label="_nolegend_")
51085129

51095130
if bottom is None:

lib/matplotlib/pyplot.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3004,23 +3004,21 @@ def stackplot(x, *args, **kwargs):
30043004
draw_if_interactive()
30053005
finally:
30063006
ax.hold(washold)
3007-
3007+
30083008
return ret
30093009

30103010
# This function was autogenerated by boilerplate.py. Do not edit as
30113011
# changes will be lost
30123012
@_autogen_docstring(Axes.stem)
3013-
def stem(x, y, linefmt='b-', markerfmt='bo', basefmt='r-', bottom=None,
3014-
label=None, hold=None):
3013+
def stem(*args, **kwargs):
30153014
ax = gca()
30163015
# allow callers to override the hold state by passing hold=True|False
30173016
washold = ax.ishold()
3018-
3017+
hold = kwargs.pop('hold', None)
30193018
if hold is not None:
30203019
ax.hold(hold)
30213020
try:
3022-
ret = ax.stem(x, y, linefmt=linefmt, markerfmt=markerfmt,
3023-
basefmt=basefmt, bottom=bottom, label=label)
3021+
ret = ax.stem(*args, **kwargs)
30243022
draw_if_interactive()
30253023
finally:
30263024
ax.hold(washold)

0 commit comments

Comments
 (0)
0