フィルターのクリア

Changing individual bar color in a bar graph matlab without for loop

1 回表示 (過去 30 日間)
Suryabhan Singh  Hada
Suryabhan Singh Hada 2019 年 3 月 29 日
回答済み: Pruthvi Muppavarapu 2019 年 4 月 1 日
I want to change individual bar color in a bar graph in Matlab. I surely can do it using for loop but is it possible to do it without using for loop something like vector operation.
This is the minimal example using for loop
distr = [11,12,34,45,9];
totalkeys = numel(distr);
color = parula(totalkeys);
hold on;
for i = 1:totalkeys
bb= bar(i-1, distr(i), 'facecolor', color(i,:),'BarWidth', 1);
end
hold off;
xlim([0 totalkeys-1]);
Btw I am using MATLAB_2016a.

回答 (1 件)

Pruthvi Muppavarapu
Pruthvi Muppavarapu 2019 年 4 月 1 日
Hello Suryabhan,
Try finding the “x” and ”y” coordinates of each bar vertices manually, create a patch object and overlay it on the original graph. Please note that though this would be faster as it avoids the overhead of calling the bar plot within a FOR loop, it would be a much more involved scripting exercise.

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by