Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Color circle at end of stem in stem plot depending on value

Tags:

matlab

I have a script that plots a Fourier series using stem(). I know that I can fill the circle at the end of the stems with stem( , 'fill'). However I would like it to only fill the circle if the magnitude is negative, or alternatively, fill all of them, but have an outer circle of another color on those that have a negative magnitude.

I tried using a variable inside stem(), and also a full if-else statement, but both returned errors.

Any way this can be done?

like image 612
jodles Avatar asked Oct 25 '25 20:10

jodles


1 Answers

You can remove marker from stem plot with 'Marker' property set to 'none'. Then add markers where ever you like with plot or scatter function. Add hold on after the stem command and hold off after all plotting commands.

For example:

x = randn(20,1);
stem(x,'Marker','none')
hold on
plot(find(x>0),x(x>0),'ro')
plot(find(x<0),x(x<0),'bx')
hold off
like image 85
yuk Avatar answered Oct 28 '25 04:10

yuk