1
votes

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.

2
Please clarify if you work with python or matlab and remove the unnecessary tags - hitzg
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! - ssinfod
Ok, thanks for clarifying that. If tom10's answer solves the problem, please accept his answer. - hitzg
I don't know how to accept an answer ! If I press the Arrow (up) it says I need a reputation of 15. - ssinfod
You have to click the check sign below the arrow. It's nicely explained here: meta.stackexchange.com/questions/5234/… - hitzg

2 Answers

4
votes

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()
1
votes

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