Remove the circular "Tips" from stem plots

Is there a way in the handles menu to eliminate the circular "tips" on stem plots? I just want vertical lines as the plots are grouped four to a figure and the circular parts get in the way of the data.
Thanks

 Accepted Answer

A slight adaptation of the example in the help to set marker size will do the trick:
figure
x = 0:25;
y = [exp(-.07*x).*cos(x);exp(.05*x).*cos(x)]';
h = stem(x, y);
set(h(1),'MarkerFaceColor','blue','MarkerSize',0)
set(h(2),'MarkerFaceColor','red','MarkerSize',0)

4 Comments

Here's the change needed for later versions, like R2017b or later:
figure
x = 0:25;
y = [exp(-.07*x).*cos(x);exp(.05*x).*cos(x)]';
h = stem(x, y);
set(h, 'Marker', 'none')
this formula looks perfect but i think somthing needs to be changed there is an indentation error in the x =0:25;
@Yohana Alemseged none of my code is indented, nor should it be, and the code runs with no error. Why do you say "somthing needs to be changed there is an indentation error in the x =0:25;" I'm not seeing any problem.
x = 0:25;
y = [exp(-.07*x).*cos(x);exp(.05*x).*cos(x)]';
h = stem(x, y);
set(h, 'Marker', 'none')

Sign in to comment.

More Answers (1)

I had a very similar problem with a program I am writing, and this Accepted Answer did not work for me, using Matlab 2017b. I modified the code slightly, and wanted to share my solution, as the accepted answer is no longer completely correct, with Matlab 2017b, at least, as the following error is thrown when setting 'MarkerSize' to zero:
Error using matlab.graphics.chart.primitive.Stem/set
Error setting property 'MarkerSize' of class 'Stem':
Value should be a finite number greater than 0
An appropriate fix to this is setting the 'Marker' property to 'none', as described below:
figure
x = 0:25;
y = [exp(-.07*x).*cos(x);exp(.05*x).*cos(x)]';
h = stem(x, y);
set(h(1),'MarkerFaceColor','blue','Marker','none')
set(h(2),'MarkerFaceColor','red','Marker','none')
Now, I used the exact code provided above. I would not format the block of code this way; I like plots to be contained in a single function call, if possible. This was just to show the concept.
Example of output:
Now, I just looked at this output, seeing as we only see one stem plot. Well, the example functions given are bad examples, as the 'blue' function is always smaller than the 'red' function.
Here is a better example:
figure
x = 0:25;
y = [exp(-.07*x).*cos(x);0.075*sqrt(x)]';
h = stem(x, y);
set(h(1),'MarkerFaceColor','blue','Marker','none')
set(h(2),'MarkerFaceColor','red','Marker','none')
Example of output:
This demonstrates that the code is actually doing what you want, for both stem plots.
The same job could be done with one line of code, and this is how I would solve the question:
stem(x, y, 'Marker','none')
  • As this is my first time ever answering a question on the Matlab Community, I hope I gave enough information!
  • Thank you Image Analyst for your input on my given answer!

2 Comments

You can just do
set(h, 'Marker', 'none')
more directly and simply. Thanks for bringing it up again. I also put the fix above in my answer to increase the probability that it will get seen.
That makes sense. I was very concerned that it was 2018 and that was how I had to fix that issue. I was thinking that, by now, this would be a common enough problem that there would be more compiler-centered solution, and not just a hack-rigged solution.
Thanks for responding to this, IA. (I am editing my solution, again, as it really isn't the best way to do it?)

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!