Making a Grantt chart, labeling individually based on vector
1 view (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Voss
on 9 Feb 2022
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
More Answers (1)
Chunru
on 9 Feb 2022
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')
0 Comments
See Also
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!