Filter löschen
Filter löschen

using fill function to make shaded area

12 Ansichten (letzte 30 Tage)
Ham Man
Ham Man am 1 Nov. 2022
Kommentiert: Ham Man am 2 Nov. 2022
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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 2 Nov. 2022
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 Kommentare
Walter Roberson
Walter Roberson am 2 Nov. 2022
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 am 2 Nov. 2022
Thank you so much Walter. That works.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by