フィルターのクリア

Making a Grantt chart, labeling individually based on vector

1 回表示 (過去 30 日間)
Luís Silva
Luís Silva 2022 年 2 月 9 日
コメント済み: Luís Silva 2022 年 2 月 9 日
Hi all
Ive managed to code a grantt char but im having problems color coding it or labeling it.
code:
D = [1,1,5;2,1,3;3,4,6;4,3,6;5,1,3;6,6,11];
B = [3,6,1,2,4,5];
hBar = barh(D, 'stacked');
hBar(1).Visible='off';
hBar(3).Visible='off';
yt = get(gca, 'YTick');
set(gca, 'YTick', yt, 'YTickLabel', {'Barreira 1' 'Barreira 2' 'Barreira 3' 'Barreira 4' 'Barreira 5' 'Barreira 6'})%Nomes barreiras
yjob = {'' '' ''};
barbase = cumsum([zeros(size(D,1),1) D(:,1:end-1)],2);
joblblpos = D/2 + barbase;
for k1 = 1:size(D,1)
text(joblblpos(k1,:), yt(k1)*ones(1,size(D,2)), yjob, 'HorizontalAlignment','center')
end
my result is this but i wanted to put the following labels in blue based on vector B
Is it possible to label it based on vector "B" ? or color code it? i cant seem to make it possible with this method
Many thanks!

採用された回答

Voss
Voss 2022 年 2 月 9 日
D = [1,1,5;2,1,3;3,4,6;4,3,6;5,1,3;6,6,11];
B = [3,6,1,2,4,5];
hBar = barh(D, 'stacked');
hBar(1).Visible='off';
hBar(3).Visible='off';
yt = get(gca, 'YTick');
set(gca, 'YTick', yt, 'YTickLabel', {'Barreira 1' 'Barreira 2' 'Barreira 3' 'Barreira 4' 'Barreira 5' 'Barreira 6'})%Nomes barreiras
yjob = arrayfun(@num2str,B,'UniformOutput',false);
barbase = cumsum([zeros(size(D,1),1) D(:,1:end-1)],2);
joblblpos = D/2 + barbase;
for k1 = 1:size(D,1)
text(joblblpos(k1,2), k1, yjob{k1}, 'HorizontalAlignment','center','Color','b','FontSize',16)
end
  1 件のコメント
Luís Silva
Luís Silva 2022 年 2 月 9 日
This solved it! didnt knew of arrayfun(). Thank you!

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

その他の回答 (1 件)

Chunru
Chunru 2022 年 2 月 9 日
D = [1,1,5;2,1,3;3,4,6;4,3,6;5,1,3;6,6,11];
B = [3,6,1,2,4,5];
hBar = barh(D, 'stacked');
hBar(1).Visible='off';
hBar(3).Visible='off';
yt = get(gca, 'YTick');
set(gca, 'YTick', yt, 'YTickLabel', {'Barreira 1' 'Barreira 2' 'Barreira 3' 'Barreira 4' 'Barreira 5' 'Barreira 6'})%Nomes barreiras
% yjob = {'' '' ''};
% barbase = cumsum([zeros(size(D,1),1) D(:,1:end-1)],2);
% joblblpos = D/2 + barbase;
% for k1 = 1:size(D,1)
% text(joblblpos(k1,:), yt(k1)*ones(1,size(D,2)), yjob, 'HorizontalAlignment','center')
% end
YEndPoints = hBar(2).YEndPoints;
YData = hBar(2).YData;
text(YEndPoints - YData/2, 1:length(YData), string(B), 'HorizontalAlignment','center', 'Color', 'Blue')

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by