필터 지우기
필터 지우기

How to change the color range on bar chart

조회 수: 4 (최근 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 CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by