필터 지우기
필터 지우기

Graph not large enough to contain thick line

조회 수: 2 (최근 30일)
IE
IE 2019년 7월 8일
댓글: Star Strider 2019년 7월 8일
The grey line here shows the average +/- one standard deviation, which is why the line is so thick. I'm trying to change the axis limits of the graph such that it can contain the whole line without it overlapping with the axes, but have so far been unsuccessful. Does anyone have a good method for this? I'm not showing any code here because this is just what it looks like with matlab's automatically generated axis limits.
  댓글 수: 6
Guillaume
Guillaume 2019년 7월 8일
편집: Guillaume 2019년 7월 8일
and the line width is (hopefully) +/- one standard deviation from that data point
It's very unlikely. As documented, the LineWidth is measured in points (= 1/72 of an inch). The acutal physical width of the line compared to other objects will therefore depends on the Units property of the figure and on the Units property of the axes. Only if both resolve to points (via explicit points or derived by normalized) will the thickness matches the standard deviation.
Star's answer is probably a lot more reliable than setting the LineWidth.
Bruno Luong
Bruno Luong 2019년 7월 8일
"but in my particular case it's at least symmetrical"
Same for me on screen, the dissymetry comes from the figure exportation, but it still shows my point.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2019년 7월 8일
Rather than plotting a thick line, use a patch object instead for the standard deviations:
x = 0:99; % Create Data
y = sin(2*pi*x/25); % Create Data
sd = rand(size(y)); % Standard Deviations
figure
plot(x, y)
hold on
patch([x, fliplr(x)], [y+sd, fliplr(y-sd)], [1 1 1]*0.8, 'EdgeColor','none')
hold off
grid
If you want the ‘y’ line in top of the patch object, plot it after you plot the patch object.
  댓글 수: 2
IE
IE 2019년 7월 8일
Thank you, I didn't consider that option. I've never worked with patch objects before, so bear with me, but I'm now getting two of the same object in the same subplot.
patch([xL',fliplr(xL')],[yL+stDev fliplr(yL-stDev)],[1 1 1]*0.9,'EdgeColor','none')
Capture.PNG
Are the constraints off?
Star Strider
Star Strider 2019년 7월 8일
My pleasure.
For my code to work correctly, ‘xL’, ‘yL’, and ‘stDev’ all must be row vectors, not column vectors, in the patch call. (They can be anything you want elsewhere in your code.) One way to be certain that they are compatible with patch is to change the patch call slightly to:
patch([xL(:)',fliplr(xL(:)')],[yL(:)'+stDev(:)', fliplr(yL(:)'-stDev(:)')],[1 1 1]*0.9,'EdgeColor','none')
I tested that patch call and it works with my test vectors. It should work in your code by simply copying it and pasting it.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Bob Thompson
Bob Thompson 2019년 7월 8일
Try here.
  댓글 수: 1
Guillaume
Guillaume 2019년 7월 8일
I believe the OP generated the graph by using a very large LineWidth to plot the grey line. The auto limits for axes don't take into account line thickness, so actual limits would have to be calculated manually.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Polygons에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by