How to change the color range on bar chart
2 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Bar Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!