How to change the color range on bar chart

2 ビュー (過去 30 日間)
endystrike
endystrike 2020 年 6 月 18 日
コメント済み: Ashwin 2020 年 6 月 18 日
Hi everyone!
Is it possible to change the color range of this bar chart?
Sometimes assets' colors seems to be too similar and it's difficult to understand to which of them each color is referred to...
Thanks a lot! :)
idx = find(sum(stocks_glob_perc)~=0);
alloc_f = figure('units','normalized','position',[0 0 1 1]); %#ok<NASGU>
ax = bar(date_ax,100*stocks_glob_perc(1:end-1,idx),'stacked','BarWidth',1);
xlim([date_ax(FirstDayOfPtot)-5 date_ax(end)+5]);
set(gca,'XTick',date_ax(EoYi+1));
ytickformat('percentage');
ylim([0 100]);
datetick('x','mm/YYYY','keeplimits','keepticks');
hlegx = legend(all_i(idx),'Location','southoutside','Orientation','horizontal','FontSize',13);

採用された回答

Ashwin
Ashwin 2020 年 6 月 18 日
My understanding is that you require a way to modify the color range of the bar graph to distinctly identify the colors being used.
A direct modification of the range may lead to the same issue you’re facing. However, using the colororder function will allow you to mention desired RGB/hex values, allowing to maintain their clear distinction.
a = [1,3,6;2,5,6;8,2,1];
H=bar(a, 'stacked');
newColors = ['#eb9234'
'#34eb86'
'#d034eb'];
colororder(newColors);
Refer to the below link for more information on how to use colororder: https://www.mathworks.com/help/matlab/ref/colororder.html
  4 件のコメント
endystrike
endystrike 2020 年 6 月 18 日
編集済み: endystrike 2020 年 6 月 18 日
Thanks a lot Ashwin,
I solved combining your answer with the usage of this function found on File Exchange... ;)
alloc_f = figure('units','normalized','position',[0 0 1 1]); %#ok<NASGU>
ax = bar(date_ax,100*stocks_glob_perc(1:end-1,idx),'stacked','BarWidth',1,'FaceColor','flat');
newColors = maxdistcolor(length(idx),@srgb_to_Jab);
for k=1:length(idx)
ax(k).CData = newColors(k,:);
end
xlim([date_ax(FirstDayOfPtot)-5 date_ax(end)+5]);
set(gca,'XTick',date_ax(EoYi+1));
ytickformat('percentage');
ylim([0 100]);
datetick('x','mm/YYYY','keeplimits','keepticks');
hlegx = legend(all_i(idx),'Location','southoutside','Orientation','horizontal','FontSize',13);
Ashwin
Ashwin 2020 年 6 月 18 日
Glad to be of help!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by