How to make error bars on double bar graph?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Chelsie Boodoo
le 30 Juil 2022
Commenté : Star Strider
le 31 Juil 2022
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
0 commentaires
Réponse acceptée
Star Strider
le 31 Juil 2022
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
