Changing the color of stacking bar plot with many groups

1 回表示 (過去 30 日間)
Yaser Khojah
Yaser Khojah 2021 年 3 月 17 日
コメント済み: Rik 2021 年 3 月 17 日
I have a big matrix with size of 28 X 10 and I used bar plot (stacking) to plot them. Now I'm struggling to change the color for all the 28 variables. Any to make them look different so i cant distinguish them.
figure
students = rand(28,10);
year = 2020: 2029;
bar(year, students, 'stacked')
legend('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'Z')

採用された回答

Rik
Rik 2021 年 3 月 17 日
students = rand(28,10);
year = 2020: 2029;
h=bar(year, students, 'stacked') ;
legend('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'Z')
c=colormap('jet');
pick=round(linspace(1,size(c,1),numel(h)));
c=mat2cell(c(pick,:),ones(1,numel(h)),3);
[h.FaceColor]=deal(c{:});
  3 件のコメント
Yaser Khojah
Yaser Khojah 2021 年 3 月 17 日
Is there a way to make some of them with grid color or something that would make them noticeable rather only by color?
Rik
Rik 2021 年 3 月 17 日
Every group will be a bar object. You can check the documentation which properties are available for you to edit.
If you can't edit all properties you want, you may need to build it yourself from patch objects instead. You could see if there is something suitable on the FileExchange.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by