필터 지우기
필터 지우기

Remove the circular "Tips" from stem plots

조회 수: 43 (최근 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 CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by