Making a Grantt chart, labeling individually based on vector
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Voss
le 9 Fév 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
Plus de réponses (1)
Chunru
le 9 Fév 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 commentaires
Voir également
Catégories
En savoir plus sur Axis Labels dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!