フィルターのクリア

How to not repeat colors plotting with barh?

20 ビュー (過去 30 日間)
Luca Repetto
Luca Repetto 2021 年 7 月 20 日
コメント済み: Luca Repetto 2021 年 7 月 28 日
Hello,
I'm plotting a Gantt chart and I have 10 jobs, as you can see from the image after the 6th job the colours are repeating themselves, how can I tell to not repeat them?
I also have another question, how can I plot inside each bar the name of the job? So that I won't have anymore to use the legend.
Thank you in advance.

採用された回答

Vineet Joshi
Vineet Joshi 2021 年 7 月 28 日
Hi
You can customize the color of the bars and make them unique using CData.
The following code might help you in the same.
X = [1];
Y10 = [5 5 5 5 5 5 5 5 5 5];
bar_obj = barh(X,Y10,'stacked','FaceColor','flat');
bar_obj(8).CData = [0 1 0];
bar_obj(9).CData = [1 1 0.5];
bar_obj(10).CData = [1 0.5 0.5];
As you can see, all the colours are unique.
Hope this helps.
Thanks
  1 件のコメント
Luca Repetto
Luca Repetto 2021 年 7 月 28 日
Ok perfect, that worked! Thank you.
I also have another question, do you know how to do a vertical dashed line with two colours in the plot?
I wanted to do a red and blue one in the picture that I attach where there are D9 & D10, but I only have found how to do a dashed line with only one colour:
xl = xline(D(scheduled(i)),'--r',"D9 & D10");

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by