-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
#5856: added option to create vertically-oriented stem plots #6168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6ca8063
e93cd3e
2b9e65f
6c406f4
56fd706
ed19281
032ff4e
9ed1e2e
9570dfa
bd7c878
b161f18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Added ``orientation`` parameter for stem plots | ||
----------------------------------- | ||
When creating stem plots, you can now pass in an ``orientation`` argument to :func:`stem`. | ||
|
||
Currently, only ``vertical`` and ``horizontal`` orientations are supported, | ||
with ``horizontal`` being the default. | ||
|
||
Example | ||
``````` | ||
stem(x, x, orientation='vertical') |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2364,8 +2364,10 @@ def stem(self, *args, **kwargs): | |
|
||
Call signatures:: | ||
|
||
stem(y, linefmt='b-', markerfmt='bo', basefmt='r-') | ||
stem(x, y, linefmt='b-', markerfmt='bo', basefmt='r-') | ||
stem(y, linefmt='b-', markerfmt='bo', basefmt='r-', | ||
orientation = {'horizontal'|'vertical'}) | ||
stem(x, y, linefmt='b-', markerfmt='bo', basefmt='r-', | ||
orientation = {'horizontal'|'vertical'}) | ||
|
||
A stem plot plots vertical lines (using *linefmt*) at each *x* | ||
location from the baseline to *y*, and places a marker there | ||
|
@@ -2374,17 +2376,39 @@ def stem(self, *args, **kwargs): | |
|
||
If no *x* values are provided, the default is (0, 1, ..., len(y) - 1) | ||
|
||
Return value is a tuple (*markerline*, *stemlines*, | ||
*baseline*). | ||
Optional parameters: | ||
-------------------- | ||
linefmt : line format string | ||
Format for the lines protruding from the baseline to the | ||
stem markers. | ||
|
||
markerfmt: marker format string | ||
Format for the markers. | ||
|
||
basefmt: line format string | ||
Format for the baseline. | ||
|
||
vertical: string, optional (horizontal) | ||
If 'vertical', will produce a vertically-oriented stem plot, | ||
else it will produce a horizontally-oriented stem plot. | ||
|
||
bottom: num, optional (0) | ||
The location of the base line. | ||
|
||
label: string | ||
Label for the stem container returned. | ||
|
||
Returns | ||
------- | ||
The return value is ``(markerline, stemlines, baseline)``. | ||
|
||
.. seealso:: | ||
This | ||
`document <http://www.mathworks.com/help/techdoc/ref/stem.html>`_ | ||
for details. | ||
|
||
|
||
**Example:** | ||
|
||
Examples | ||
-------- | ||
.. plot:: mpl_examples/pylab_examples/stem_plot.py | ||
""" | ||
remember_hold = self._hold | ||
|
@@ -2420,22 +2444,42 @@ def stem(self, *args, **kwargs): | |
except IndexError: | ||
basefmt = kwargs.pop('basefmt', 'r-') | ||
|
||
# Check the orientation variable to see if the user | ||
# wants a vertical or horizontal stem plot | ||
orientation = kwargs.pop('orientation', 'horizontal') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should probably do some validation here to make sure 'aardvark' or the like does not get passed in. |
||
|
||
if orientation not in ('horizontal', 'vertical'): | ||
raise ValueError("'%s' is not a valid orientation" % orientation) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a bigger change, but could you refactor this to have on |
||
bottom = kwargs.pop('bottom', None) | ||
label = kwargs.pop('label', None) | ||
|
||
if orientation == 'vertical': | ||
x, y = y, x | ||
|
||
markerline, = self.plot(x, y, markerfmt, label="_nolegend_") | ||
|
||
if bottom is None: | ||
bottom = 0 | ||
|
||
stemlines = [] | ||
for thisx, thisy in zip(x, y): | ||
l, = self.plot([thisx, thisx], [bottom, thisy], linefmt, | ||
label="_nolegend_") | ||
if orientation == 'vertical': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this if block be eliminated? |
||
thisx, thisy = thisy, thisx | ||
l, = self.plot([bottom, thisy], [thisx, thisx], linefmt, | ||
label="_nolegend_") | ||
else: | ||
l, = self.plot([thisx, thisx], [bottom, thisy], linefmt, | ||
label="_nolegend_") | ||
stemlines.append(l) | ||
|
||
baseline, = self.plot([np.amin(x), np.amax(x)], [bottom, bottom], | ||
basefmt, label="_nolegend_") | ||
if orientation == 'vertical': | ||
x, y = y, x | ||
baseline, = self.plot([bottom, bottom], [np.amin(x), np.amax(x)], | ||
basefmt, label="_nolegend_") | ||
else: | ||
baseline, = self.plot([np.amin(x), np.amax(x)], [bottom, bottom], | ||
basefmt, label="_nolegend_") | ||
|
||
self.hold(remember_hold) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not conform with numpy doc specs see #6240 for a similar fix.
If you change it to
Other Parameters
it should work. As it is this section will not be in the web generated version of the docs.See https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt for more numpy docs info.
The output from the docs build should this is in https://travis-ci.org/matplotlib/matplotlib/jobs/118347853#L1036