Problem adding labels to figure
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Juan David Parra Quintero
il 18 Lug 2023
Commentato: Star Strider
il 18 Lug 2023
I am trying to make a figure but when I give the values to the label they are not reflected on the figure. My vector in the X axis was named as x3, however these values are not reflected in the graph. How should I proceed to do this? Thank you very much.
fig=figure(3);
clf;
x3=[Bicicleta; Microbus; Motocicleta; Vehiculo; Tractocamion];
y3 = [1 1 1; 219 65 4; 300 828 36; 986 250 10; 0 0 10];
b3=bar(x3,y3);
ylim([0 1100])
xtips3 = b3(1).XEndPoints;
ytips3 = b3(1).YEndPoints;
labels3 = string(b3(1).YData);
text(xtips3,ytips3,labels3,'HorizontalAlignment','center',...
'VerticalAlignment','bottom')
xtips3 = b3(2).XEndPoints;
ytips3 = b3(2).YEndPoints;
labels3 = string(b3(2).YData);
text(xtips3,ytips3,labels3,'HorizontalAlignment','center',...
'VerticalAlignment','bottom')
xtips3 = b3(3).XEndPoints;
ytips3 = b3(3).YEndPoints;
labels3 = string(b3(3).YData);
text(xtips3,ytips3,labels3,'HorizontalAlignment','center',...
'VerticalAlignment','bottom')
legend('Accidente','Lesionado','Muerte')
xlabel("Agente causante");
ylabel("Número de agentes");
2 Commenti
Risposta accettata
Star Strider
il 18 Lug 2023
One problem is that just after creating the figure the code clears it.
Otherwise perhaps something like this —
fig=figure(3);
% clf;
x3=categorical(["Bicicleta"; "Microbus"; "Motocicleta"; "Vehiculo"; "Tractocamion"]);
y3 = [1 1 1; 219 65 4; 300 828 36; 986 250 10; 0 0 10];
b3=bar(x3,y3);
ylim([0 1100])
xtips3 = b3(1).XEndPoints;
ytips3 = b3(1).YEndPoints;
labels3 = string(b3(1).YData);
text(xtips3,ytips3,labels3,'HorizontalAlignment','center',...
'VerticalAlignment','bottom')
xtips3 = b3(2).XEndPoints;
ytips3 = b3(2).YEndPoints;
labels3 = string(b3(2).YData);
text(xtips3,ytips3,labels3,'HorizontalAlignment','center',...
'VerticalAlignment','bottom')
xtips3 = b3(3).XEndPoints;
ytips3 = b3(3).YEndPoints;
labels3 = string(b3(3).YData);
text(xtips3,ytips3,labels3,'HorizontalAlignment','center',...
'VerticalAlignment','bottom')
legend('Accidente','Lesionado','Muerte', 'Location','NW')
xlabel("Agente causante");
ylabel("Número de agentes");
.
4 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Orange in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!