HOW CAN I CHANGE THE COLOR OF DIFFERENT DATA?
13 views (last 30 days)
Show older comments
Pul on 25 May 2021
I should change the colour of red data: on the right I should use a color and on the left another one; is it possible?
Uday Pradhan on 28 May 2021
If you would like to color the vertical bars in an errorbar plot individually, you could try replicating the errorbar plot using the below script:
%Create dummy data and errors
%Sprinkle some NaNs over the error data
e(randi(max(x),[1 10])) = NaN;
%Plot the data
%Choose length of the whisker for errorbars
inc = 0.25;
%Set your special condition to switch colors for the vertical bars
if mod(i,2) == 0
color = 'r';
color = 'k';
%Plot the vertical bar
plot([x(i) x(i)],[y(i)-e(i) y(i)+e(i)],'Color',color);
%Plot the whiskers
plot([x(i)-inc x(i)+inc],[y(i)-e(i) y(i)-e(i)],'Color',color);
plot([x(i)-inc x(i)+inc],[y(i)+e(i) y(i)+e(i)],'Color',color);
You could replace x,y and e with your data and set your criteria to color each bar differently. I hope this helps.
More Answers (0)
Find more on Box Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!