using fill function to make shaded area
38 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Akzeptierte Antwort
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
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!