Making a Grantt chart, labeling individually based on vector
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Luís Silva
am 9 Feb. 2022
Kommentiert: Luís Silva
am 9 Feb. 2022
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/888375/image.png)
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 Kommentare
Akzeptierte Antwort
Voss
am 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
Weitere Antworten (1)
Chunru
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Axis Labels finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!