1

I want to draw 2 stem plots on the same figure. Here is an example: enter image description here

I found this stem plot example from the matplotlib: http://matplotlib.org/examples/pylab_examples/stem_plot.html

However, I don't see how to add an offset to the stem plot. (+1 or +2 on Y axis).

Maybe another plot type could also work for me ? I want to display small events with vertical bars.

This feature would be similar to the "BaseValue" from the Matlab stem plot.

5
  • Please clarify if you work with python or matlab and remove the unnecessary tags Commented Apr 1, 2015 at 11:25
  • I work with python (matplotlib), but I'm looking for the equivalent feature of "BaseValue" from matlab. It seems tom10 gave a valid answer to me. thanks! Commented Apr 1, 2015 at 12:21
  • 1
    Ok, thanks for clarifying that. If tom10's answer solves the problem, please accept his answer. Commented Apr 1, 2015 at 13:17
  • I don't know how to accept an answer ! If I press the Arrow (up) it says I need a reputation of 15. Commented Apr 2, 2015 at 1:49
  • You have to click the check sign below the arrow. It's nicely explained here: meta.stackexchange.com/questions/5234/… Commented Apr 2, 2015 at 7:50

2 Answers 2

4

You can use the keyword, bottom.

enter image description here

from pylab import *

x = linspace(0.1, 2*pi, 10)
markerline, stemlines, baseline = stem(x, cos(x), '-.', bottom=.5)
setp(markerline, 'markerfacecolor', 'b')
setp(baseline, 'color','r', 'linewidth', 2)

show()
Sign up to request clarification or add additional context in comments.

Comments

1

Using refline as a workaround in Matlab two stem plots can be displayed as you required.

clear all;

x = 1:5;
y1 = [1, 0, -1, 0, 1];
y2 = [-.5, 1, .5, -1, 0];

b1 = 0; % base line for y1
b2 = -2; % base line for y2

y1 = y1 + b1;
y2 = y2 + b2;

y = [y1; y2]';

h = stem(x,y);

set(h(1), 'BaseValue' , b1);
set(h(2), 'BaseValue' , b2);

hold on;

refline(0,b1); % refline was used a workaround

axis([1 5 -5 5])

Figure:

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.