Display values in bar plot (app designer)

30 visualizaciones (últimos 30 días)
Shahar ben ezra
Shahar ben ezra el 30 de Sept. de 2020
Comentada: Benjamin Kraus el 10 de Jul. de 2023
I have a problem with the code,
Why do I not see values ​​in a graph like in Figure
Notice the yellow in the picture
X = categorical({'Small','Medium','Large'});
X = reordercats(X,{'Small','Medium','Large'});
Y = [2 3 6];
bar(X,Y);
b = bar(app.UIAxes,X,Y);
for i=1:1:length(X)
text(i:i,Y(i)',num2str(Y(i)','%0.2f'),'HorizontalAlignment','center','VerticalAlignment','bottom')
box off
end

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 30 de Sept. de 2020
Pass app.UIAxes as first argument of text()
text(app.UIAxes, i:i, Y(i)', num2str(Y(i)','%0.2f'),'HorizontalAlignment','center','VerticalAlignment','bottom')

Más respuestas (4)

Shahar ben ezra
Shahar ben ezra el 15 de Oct. de 2020
Thank you! @Ameer Hamza

Shahar ben ezra
Shahar ben ezra el 30 de Sept. de 2020
THIS IS WORK TNXX!!!!
but do you know way the figure pop up?
i fix my code to this :
X = categorical({'Small','Medium','Large'});
X = reordercats(X,{'Small','Medium','Large'});
Y = [2 3 6];
bar(app.UIAxes,X,Y);
for i=1:1:length(X)
text(app.UIAxes, i:i, Y(i)', num2str(Y(i)','%0.2f'),'HorizontalAlignment','center','VerticalAlignment','bottom')
box off
end
  1 comentario
Ameer Hamza
Ameer Hamza el 1 de Oct. de 2020
In app designer, pass the handle of the UIAxes object to all graphical functions. Otherwise a window will pop-up
box(app.UIAxes, "off")

Iniciar sesión para comentar.


Sara Macchiavello
Sara Macchiavello el 28 de Nov. de 2020
Hi!
I'd like to know how can I set the values inside the bar plot, just like this:
I obtain the following bar plot using the code above but I can't place values in the correct center position.
b = bar(X,Y);
hold on
b.FaceColor = 'flat';
b.CData(1,:) = [0 0.447 0.741]; % color editing
b.CData(2,:) = [0.850 0.325 0.098];
b.CData(3,:) = [0.466 0.674 0.188];
b.FaceAlpha = .7; % opacity
text(1:length(Y),Y,num2str(Y'),'vert','bottom','horiz','center'); % values position
std = [2.1 4.4 6]; % standard deviation
er = errorbar(X,Y,std);
er.Color = [0 0 0];
er.LineStyle = 'none';
set(gca, 'ytick', []);
box off
Can you help me, please?
Thank you,
Sara
  1 comentario
Benjamin Kraus
Benjamin Kraus el 2 de Dic. de 2020
Sara,
You are more likely to get an answer if you post a new question to MATLAB Answers, rather than add to an existing question.
As long as you are not using a stacked bar plot, I think all you need to do in your case is divide Y by two and switch the vertical alignment from bottom to middle.
text(1:length(Y),Y/2,num2str(Y'),'vert','middle','horiz','center');

Iniciar sesión para comentar.


omar shirko
omar shirko el 8 de Jul. de 2023
%Greeting
% I encountered an issue with values displayed above the bar. To enhance accuracy, I need to reduce the font size.
% The applying code as follow
q = [0.3 0.35 0.4 0.28 0.6];
kl = 256; % key length
sm = 25; % number of simulation run
g = zeros(1,sm); % Initiallize the sum to zero
g2 = zeros(1,sm); % Initiallize the sum to zero
z = zeros(1,sm); % Initiallize the sum to zero
figure;
v1=0;
v2=0;
for j =1:sm
N = randi([1 5],1);
y = 0;
y2 = 0;
for k = 1:N
y = y+ q(k)*kl; % computing the sum
end
y2 = N * kl;
g(j) = y;
g2(j) = y2;
%z(j) = [y y2];
v1 = v1 + y;
v2 = v2 + y2;
end
hold on;
xx = 1:sm;
%g= sort(g);
%g2= sort(g2);
%z = [g, g2];
%bar(g2,0.6);
%hold on;
%bar(g,0.4);
subplot(2,2,1);
bar(xx-0.25,g2,0.4,'red');
hold on;
bar(xx+0.25,g,0.4,'blue');
axis([0 26 0 1300])
title('Sample 1');
xlabel('Simulation Number');
ylabel('Total Generated Keys (bits)');
legend('Without SDQTRF', 'With SDQTRF');
text(1:length(g2),g2,num2str(g2'),'vert','bottom','horiz','center');
text(1:length(g),g,num2str(g'),'vert','bottom','horiz','center');
box on
  1 comentario
Benjamin Kraus
Benjamin Kraus el 10 de Jul. de 2023
You are more likely to get an answer if you post a new question to MATLAB Answers, rather than add an answer to an existing question.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by