Remove the circular "Tips" from stem plots

74 ビュー (過去 30 日間)
William
William 2013 年 1 月 18 日
コメント済み: Image Analyst 2021 年 12 月 15 日
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

採用された回答

Image Analyst
Image Analyst 2013 年 1 月 18 日
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 件のコメント
Yohana  Alemseged
Yohana Alemseged 2021 年 12 月 14 日
this formula looks perfect but i think somthing needs to be changed there is an indentation error in the x =0:25;
Image Analyst
Image Analyst 2021 年 12 月 15 日
@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')

サインインしてコメントする。

その他の回答 (1 件)

Dillon Buffone
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
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
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?)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by