code for this type of GROUP bar graph?
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Anton Kogios
2023 年 10 月 5 日
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 件のコメント
Anton Kogios
2023 年 10 月 6 日
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]);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Bar Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!