필터 지우기
필터 지우기

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개)

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 CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by