HOW CAN I CHANGE THE COLOR OF DIFFERENT DATA?

6 ビュー (過去 30 日間)
Pul
Pul 2021 年 5 月 25 日
編集済み: Pul 2021 年 6 月 12 日
Hello everyone,
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?
Thank you!
  2 件のコメント
Scott MacKenzie
Scott MacKenzie 2021 年 5 月 25 日
It would help if you included your data as a file rather than as a screen snip.
Pul
Pul 2021 年 5 月 26 日
Right; done.

サインインしてコメントする。

採用された回答

Uday Pradhan
Uday Pradhan 2021 年 5 月 28 日
Hi Pul,
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
x=1:30;
y=rand(length(x),1);
e=rand(length(x),1);
%Sprinkle some NaNs over the error data
e(randi(max(x),[1 10])) = NaN;
%Plot the data
figure
plot(x,y,'c');hold on;
%Choose length of the whisker for errorbars
inc = 0.25;
for i=1:length(x)
%Set your special condition to switch colors for the vertical bars
if mod(i,2) == 0
color = 'r';
else
color = 'k';
end
%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);
end
You could replace x,y and e with your data and set your criteria to color each bar differently. I hope this helps.
  1 件のコメント
Pul
Pul 2021 年 5 月 31 日
Hi Uday,
yes,thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeErrorbars についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by