code for this type of GROUP bar graph?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Francesco Marchione
il 4 Ott 2023
Commentato: Anton Kogios
il 6 Ott 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!
0 Commenti
Risposta accettata
Anton Kogios
il 5 Ott 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 Commenti
Anton Kogios
il 6 Ott 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]);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Bar Plots 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!