How to make error bars on double bar graph?

7 ビュー (過去 30 日間)
Chelsie Boodoo
Chelsie Boodoo 2022 年 7 月 30 日
コメント済み: Star Strider 2022 年 7 月 31 日
Hi i am trying to get error bars on my double bar graphs but it wont show. I am using MATLAB R2020a. Please help!
y=[6 8;8 10; 9 99;19 68;20 52;];
x = [categorical({'Control' , 'Target', 'NT1', 'NT2', 'NT3'})];
bar(x,y)
figure;
hold on
b= bar(x, y);
ax = gca;
ax.FontSize = 14;
xlabel("Sample", 'FontSize', 20);
ylabel("Peaks", 'FontSize', 20);
title("Specificity", 'FontSize', 26);
error_data=[];
error_data= [1 2; 1 3; 8 3; 4 2; 2 2;];
errorbar(x, y, error_data,'k','linestyle','none');
errorbar(x, y, error_data,'k','linestyle','none');
hold off

採用された回答

Star Strider
Star Strider 2022 年 7 月 31 日
I have no idea when XEndPoints and YEndPoints was introduced, however it was relatively recently (within the last few years).
This works in R2022a
y=[6 8;8 10; 9 99;19 68;20 52;];
error_data= [1 2; 1 3; 8 3; 4 2; 2 2;];
x = [categorical({'Control' , 'Target', 'NT1', 'NT2', 'NT3'})];
figure
hold on
hb = bar(x, y);
for k = 1:numel(hb)
errorbar(hb(k).XEndPoints, hb(k).YEndPoints, error_data(:,k), '.k', 'MarkerSize',0.1)
end
ax = gca;
ax.FontSize = 14;
xlabel("Sample", 'FontSize', 20);
ylabel("Peaks", 'FontSize', 20);
title("Specificity", 'FontSize', 26);
If this doesn’t work in your version, go here for an alternative approach that probably will. (It fails in R2022a since XOffset may no longer exist, so I cannot illustrate it here.)
.
  2 件のコメント
Chelsie Boodoo
Chelsie Boodoo 2022 年 7 月 31 日
Thanks it worked!!!!
Star Strider
Star Strider 2022 年 7 月 31 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by