code for this type of GROUP bar graph?

2 visualizaciones (últimos 30 días)
Francesco Marchione
Francesco Marchione el 4 de Oct. de 2023
Comentada: Anton Kogios el 6 de Oct. de 2023
I would like to plot this graph with font in LATEX.
The data are just numbers (known from experiments).
In addition, I would also like to add the error (standard deviation) on each bar (known number).
Can you help me in writing the code?
Thanks a lot!

Respuestas (1)

Anton Kogios
Anton Kogios el 5 de Oct. de 2023
This isn't exactly the same as your plot, but I hope it helps. If you want a patterned fill on your bars, you can check out Hatchfill2 (see some examples here). You may have to convert it to a histogram or play around with the bars if you don't want space between the bars.
% Generate data
y = zeros(5,4);
for i = 1:5
y(i,:) = (6-i)*10 + randi(10,[1,4]);
end
% Plot bar graph
figure(1);clf
b = bar(1:5,y,'FaceAlpha',0.55);
b(1).FaceColor = [0.9290 0.6940 0.1250];
b(2).FaceColor = [0.4660 0.6740 0.1880];
b(3).FaceColor = [0.4940 0.1840 0.5560];
b(4).FaceColor = [1 1 0];
% Axis ticks
xticklabels({'R','200','400','600','800'})
a = gca;
a.TickLabelInterpreter = 'latex';
a.FontSize = 12;
% Labels and legend
xlabel('Temperature in $^\circ$C','Interpreter','latex','FontSize',13)
ylabel('Compressive Strength (MPa)','Interpreter','latex','FontSize',13)
legend({'GPC (Control)','10\% GP-A','20\% GP-A','30\% GP-A'}, ...
'Interpreter','latex','FontSize',12)
% Errorbars
hold on
sd = randi(3,5,4);
errorbar([b.XEndPoints],[b.YEndPoints],sd(:), ...
'Color','k','LineStyle','none','HandleVisibility','off')
hold off
  2 comentarios
Francesco Marchione
Francesco Marchione el 6 de Oct. de 2023
Thank you so much!
Just one more question (I am very novice, please help me)...
How can I write in order to report precise values both for data and errors?
E.g., I have
R=(45, 55, 49, 70) and errors +-5; +-2; +-1; +-8
200=(75, 49, 49, 60) and errors +-5; +-2; +-1; +-8
400=(64, 37, 49, 50) and errors +-5; +-2; +-1; +-8
600=(42, 35, 49, 40) and errors +-5; +-2; +-1; +-8
800=(20, 20, 10, 9) and errors +-5; +-2; +-1; +-8
I would like to put my precise numbers instead of a function given by the cyle FOR.
Thank you for your patience.
Anton Kogios
Anton Kogios el 6 de Oct. de 2023
No worries! You should be able to figure this out yourself if you look at what y and sd look like by removing the semicolon at the end of the line. You can also tell by the size of the arrays.
To point you in the right direction, both y and sd have 5 rows (one for each of the groups) and 4 columns (one for each element in the group). So, in your case something like this should work:
y = [45,55,49,70; % R
75,49,49,60; % 200
64,37,49,50; % 400
42,35,49,40; % 600
20,20,10,9]; % 800
sd = repmat([5,2,1,8],[5,1]);

Iniciar sesión para comentar.

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by