Problem adding labels to figure
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Star Strider
2023-7-18
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Orange 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!