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
采纳的回答
更多回答(1 个)
Dillon Buffone
2018-3-31
编辑:Dillon Buffone
2018-4-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 个评论
Image Analyst
2018-4-1
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.
Dillon Buffone
2018-4-1
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?)
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
