Why is my errorbar not the same in each direction?
1 view (last 30 days)
Show older comments
I have a problem with my errorbars in the figure at the bottom. I want my standard deviation to be the same value in both the negative and postive vertical direction. However, the values are not the same (example glucose 2nd point).
growth = readtable("growthWT2.xlsx")
time = growth.Time_h_;
timeOD = growth.Time_h__1;
DO_1 = growth.O21;
DO_2 = growth.O22;
DO_3 = growth.O23;
mean_DO = growth.MeanO2;
S_DO = [DO_1 DO_2 DO_3];
stand_DO = std(S_DO,0,2);
pH_1 = growth.pH1;
pH_2 = growth.pH2;
pH_3 = growth.pH3;
mean_pH = growth.meanPH;
S_pH = [pH_1 pH_2 pH_3];
stand_pH = std(S_pH,0,2);
Bio_1 = growth.biomass1;
Bio_2 = growth.biomass2;
Bio_3 = growth.biomass3;
mean_bio = growth.MeanBio;
S_bio = [Bio_1 Bio_2 Bio_3];
stand_bio = std(S_bio,0,2);
glu_1 = growth.glucose1;
glu_2 = growth.glucose2;
glu_3 = growth.glucose2_1;
mean_glu = growth.meanGlucose;
S_glu = [glu_1 glu_2 glu_3];
stand_glu = std(S_glu,0,2);
ace_1 = growth.acetate1;
ace_2 = growth.acetate2;
ace_3 = growth.acetate3;
mean_ace = growth.meanAcetate;
S_ace = [ace_1 ace_2 ace_3];
stand_ace = std(S_ace,0,2);
% mean values
t = tiledlayout(2,1);
nexttile
yyaxis left
pDO = fill([time; flip(time)], [mean_DO+stand_DO; flip(mean_DO-stand_DO)], 'b', 'FaceAlpha', 0.3, 'EdgeColor', 'none');
hold on
p1DO = plot(time, mean_DO, '-', 'Color', '[0 0.4470 0.7410]');
ylabel('DO%', 'Color', 'k')
yyaxis right
pPH = fill([time; flip(time)], [mean_pH+stand_pH; flip(mean_pH-stand_pH)], 'r', 'FaceAlpha', 0.3, 'EdgeColor', 'none');
hold on
p1PH = plot(time,mean_pH, '-', 'Color', '[0.6350 0.0780 0.1840]');
ylabel('pH', 'Color', 'k')
legend([p1DO p1PH], {'DO' ,'pH'})
ylim([6.7 7.4])
ax = gca;
ax.YAxis(1).Color = 'k';
ax.YAxis(2).Color = 'k';
nexttile
yyaxis left
pOD = plot(timeOD,mean_bio,'-o', 'Color','[0.4940 0.1840 0.5560]', 'MarkerFaceColor', '[0.4940 0.1840 0.5560]');
hold on
errorbar(timeOD, mean_bio, stand_bio, 'LineStyle', 'none', 'Color', '[0.4940 0.1840 0.5560]')
ylabel('Biomass [g/L]', 'Color', 'k')
yyaxis right
pGLU = plot(timeOD,glu_1, '-s', 'Color','[0.8500 0.3250 0.0980]', 'MarkerFaceColor', '[0.8500 0.3250 0.0980]');
hold on
errorbar(timeOD, mean_glu, stand_glu, 'LineStyle', 'none', 'Color', '[0.8500 0.3250 0.0980]')
hold off
hold on
pACE = plot(timeOD,ace_1, '-^', 'Color','[0.4660 0.6740 0.1880]', 'MarkerFaceColor', '[0.4660 0.6740 0.1880]');
hold on
errorbar(timeOD, mean_ace, stand_ace, 'LineStyle', 'none', 'Color', '[0.4660 0.6740 0.1880]')
ylabel('Glucose and acetate [g/L]', 'Color', 'k')
legend([pOD pGLU pACE], {'Biomass' ,'Glucose', 'Acetate'})
ax = gca;
ax.YAxis(1).Color = 'k';
ax.YAxis(2).Color = 'k';
xlabel(t,'Time [h]')
0 Comments
Accepted Answer
Voss
on 4 Jun 2024
Edited: Voss
on 4 Jun 2024
The errorbars are centered around the means (e.g., mean_glu), but the other lines plotted with markers are not using the means (e.g., glu_1).
I'll set the errorbars LineStyle to '--' in the plot below to highlight the difference. Note that, e.g., the glucose errorbar at Time=3h is centered on the dotted line (which is at approx. 3.34) but not the square marker (which is at approx. 3.80).
growth = readtable("growthWT2.xlsx")
time = growth.Time_h_;
timeOD = growth.Time_h__1;
DO_1 = growth.O21;
DO_2 = growth.O22;
DO_3 = growth.O23;
mean_DO = growth.MeanO2;
S_DO = [DO_1 DO_2 DO_3];
stand_DO = std(S_DO,0,2);
pH_1 = growth.pH1;
pH_2 = growth.pH2;
pH_3 = growth.pH3;
mean_pH = growth.meanPH;
S_pH = [pH_1 pH_2 pH_3];
stand_pH = std(S_pH,0,2);
Bio_1 = growth.biomass1;
Bio_2 = growth.biomass2;
Bio_3 = growth.biomass3;
mean_bio = growth.MeanBio;
S_bio = [Bio_1 Bio_2 Bio_3];
stand_bio = std(S_bio,0,2);
glu_1 = growth.glucose1;
glu_2 = growth.glucose2;
glu_3 = growth.glucose2_1;
mean_glu = growth.meanGlucose;
S_glu = [glu_1 glu_2 glu_3];
stand_glu = std(S_glu,0,2);
ace_1 = growth.acetate1;
ace_2 = growth.acetate2;
ace_3 = growth.acetate3;
mean_ace = growth.meanAcetate;
S_ace = [ace_1 ace_2 ace_3];
stand_ace = std(S_ace,0,2);
% mean values
t = tiledlayout(2,1);
nexttile
yyaxis left
pDO = fill([time; flip(time)], [mean_DO+stand_DO; flip(mean_DO-stand_DO)], 'b', 'FaceAlpha', 0.3, 'EdgeColor', 'none');
hold on
p1DO = plot(time, mean_DO, '-', 'Color', '[0 0.4470 0.7410]');
ylabel('DO%', 'Color', 'k')
yyaxis right
pPH = fill([time; flip(time)], [mean_pH+stand_pH; flip(mean_pH-stand_pH)], 'r', 'FaceAlpha', 0.3, 'EdgeColor', 'none');
hold on
p1PH = plot(time,mean_pH, '-', 'Color', '[0.6350 0.0780 0.1840]');
ylabel('pH', 'Color', 'k')
legend([p1DO p1PH], {'DO' ,'pH'})
ylim([6.7 7.4])
ax = gca;
ax.YAxis(1).Color = 'k';
ax.YAxis(2).Color = 'k';
nexttile
yyaxis left
pOD = plot(timeOD,mean_bio,'-o', 'Color','[0.4940 0.1840 0.5560]', 'MarkerFaceColor', '[0.4940 0.1840 0.5560]');
hold on
errorbar(timeOD, mean_bio, stand_bio, 'LineStyle', '--', 'Color', '[0.4940 0.1840 0.5560]')
ylabel('Biomass [g/L]', 'Color', 'k')
mean_glu
glu_1
yyaxis right
pGLU = plot(timeOD,glu_1, '-s', 'Color','[0.8500 0.3250 0.0980]', 'MarkerFaceColor', '[0.8500 0.3250 0.0980]');
hold on
errorbar(timeOD, mean_glu, stand_glu, 'LineStyle', '--', 'Color', '[0.8500 0.3250 0.0980]')
hold off
hold on
pACE = plot(timeOD,ace_1, '-^', 'Color','[0.4660 0.6740 0.1880]', 'MarkerFaceColor', '[0.4660 0.6740 0.1880]');
hold on
errorbar(timeOD, mean_ace, stand_ace, 'LineStyle', '--', 'Color', '[0.4660 0.6740 0.1880]')
ylabel('Glucose and acetate [g/L]', 'Color', 'k')
legend([pOD pGLU pACE], {'Biomass' ,'Glucose', 'Acetate'})
ax = gca;
ax.YAxis(1).Color = 'k';
ax.YAxis(2).Color = 'k';
xlabel(t,'Time [h]')
3 Comments
More Answers (0)
See Also
Categories
Find more on Errorbars in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!