필터 지우기
필터 지우기

using fill function to make shaded area

조회 수: 22 (최근 30일)
Ham Man
Ham Man 2022년 11월 1일
댓글: Ham Man 2022년 11월 2일
Hi every one!
Is it possible to draw a shaded area (e.g., +- STD of a value) when we have a categorical values on x-axis?
Based on the screenshot I want AA,BB,CC instead of the numbers.(dash line is a value and the shaded area around it can be plus/minus STD)
Many thanks.

채택된 답변

Walter Roberson
Walter Roberson 2022년 11월 2일
x = categorical({'AA', 'BB', 'CC'});
yraw = rand(50,3);
ymean = mean(yraw,1);
plot(x, ymean, 'b');
s = std(yraw, [], 1);
hold on
fill([x, fliplr(x)], [ymean-s, fliplr(ymean+s)], 'k', 'FaceAlpha', 0.1 )
hold off
  댓글 수: 4
Walter Roberson
Walter Roberson 2022년 11월 2일
Use reordercats to get the order the way you want. The default order is alphanumeric, and dp1200 is before dp500 because the comparison proceeds from the beginning and '1' is before '5'
would it be possible to start a bit before AA and ends a bit after CC
You would need to add additional categories -- for example if you wanted to start 1/10 before AA you would need 32 or so categories in which AA was the 2nd category, CC was the 31'st category, and BB was the middle. And you would probably need to use xticks([AA, BB, CC]) so you got ticks at the right place.
The alternative would be to switch to a numeric axes instead of a categorical axes, and use xticks() to place the marks numerically and xlabels() to write in the appropriate category names.
Ham Man
Ham Man 2022년 11월 2일
Thank you so much Walter. That works.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by