Problem adding labels to figure

1 visualizzazione (ultimi 30 giorni)
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];
Unrecognized function or variable 'Bicicleta'.
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
Matt J
Matt J il 18 Lug 2023
Modificato: Matt J il 18 Lug 2023
Running your code produces errors (see above). Please post sufficient code so that it can be run in the forum and the problem reproduced.
Juan David Parra Quintero
Juan David Parra Quintero il 18 Lug 2023
Matt J muchas gracias ya pude correr el codigo. un saludo muy grande.

Accedi per commentare.

Risposta accettata

Star Strider
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");
See the documentation for string and categorical for details on them.
.
  4 Commenti
Juan David Parra Quintero
Juan David Parra Quintero il 18 Lug 2023
Excelente muchisimas gracias!
Star Strider
Star Strider il 18 Lug 2023
As always, my pleasure!

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by