Borrar filtros
Borrar filtros

Why is my errorbar not the same in each direction?

1 visualización (últimos 30 días)
Alexander
Alexander el 4 de Jun. de 2024
Comentada: Voss el 4 de Jun. de 2024
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")
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
growth = 167x23 table
Time_s_ Time_h_ O21 O22 O23 MeanO2 pH1 pH2 pH3 meanPH Time_h__1 biomass1 biomass2 biomass3 MeanBio glucose1 glucose2 glucose2_1 meanGlucose acetate1 acetate2 acetate3 meanAcetate ________ __________ ______ ______ ______ ______ ______ ______ ______ ______ __________ ________ ________ ________ _______ ________ ________ __________ ___________ ________ ________ ________ ___________ 0.016667 0.00027778 96.27 95.987 97.441 96.566 7.1426 7.1451 7.1513 7.1463 0.00027778 0.2268 0.2268 0.2268 0.2268 5.7814 5.7814 5.7814 5.7814 0 0 0 0 2.0167 0.033611 97.081 96.795 98.079 97.318 7.1437 7.1419 7.1533 7.1463 1.0022 0.3888 0.3888 0.3888 0.3888 5.5822 5.6066 5.5281 5.5723 0 0 0 0 4.0181 0.066968 97.308 97.221 97.494 97.341 7.1432 7.1404 7.1493 7.1443 2.019 0.648 0.684 0.648 0.66 4.8773 4.7999 4.7839 4.8204 0.1385 0.1235 0.1302 0.13073 6.0245 0.10041 97.855 97.322 98.725 97.967 7.143 7.1476 7.1544 7.1483 3.0364 1.152 1.152 1.152 1.152 3.8046 3.8166 2.4116 3.3443 0.2309 0.2066 0.4908 0.30943 8.0249 0.13375 97.88 97.83 98.239 97.983 7.1425 7.151 7.1519 7.1485 4.0271 1.872 1.8 1.8 1.824 2.2973 2.2808 2.3323 2.3035 0.3196 0.3562 0.3517 0.3425 10.033 0.16722 98.186 97.79 98.525 98.167 7.1375 7.1414 7.1472 7.142 5.0078 2.88 3.096 3.024 3 0 0 0 0 0.4614 0.4407 0.4475 0.44987 12.033 0.20056 97.945 98.183 98.139 98.089 7.1409 7.1454 7.1546 7.147 6.0765 2.88 2.808 2.952 2.88 NaN NaN NaN NaN NaN NaN NaN NaN 14.033 0.23389 97.819 97.924 98.216 97.986 7.142 7.1469 7.1535 7.1475 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 16.037 0.26729 97.274 97.864 98.266 97.801 7.1402 7.148 7.1533 7.1472 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 18.05 0.30083 97.123 98.062 97.506 97.564 7.1395 7.147 7.1457 7.1441 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 20.052 0.33419 97.303 97.832 98.004 97.713 7.1389 7.1457 7.1473 7.1439 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 22.057 0.36762 97.603 97.078 97.568 97.416 7.1275 7.1453 7.1441 7.139 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 24.067 0.40111 96.798 97.353 97.74 97.297 7.1311 7.1367 7.1431 7.1369 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 26.067 0.43444 96.964 97.436 97.395 97.265 7.1332 7.1354 7.1466 7.1384 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 28.072 0.46787 96.634 97.466 97.323 97.141 7.1336 7.1385 7.15 7.1407 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 30.083 0.50139 96.133 96.895 96.742 96.59 7.1266 7.1438 7.1486 7.1396 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
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]')

Respuesta aceptada

Voss
Voss el 4 de Jun. de 2024
Editada: Voss el 4 de Jun. de 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")
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
growth = 167x23 table
Time_s_ Time_h_ O21 O22 O23 MeanO2 pH1 pH2 pH3 meanPH Time_h__1 biomass1 biomass2 biomass3 MeanBio glucose1 glucose2 glucose2_1 meanGlucose acetate1 acetate2 acetate3 meanAcetate ________ __________ ______ ______ ______ ______ ______ ______ ______ ______ __________ ________ ________ ________ _______ ________ ________ __________ ___________ ________ ________ ________ ___________ 0.016667 0.00027778 96.27 95.987 97.441 96.566 7.1426 7.1451 7.1513 7.1463 0.00027778 0.2268 0.2268 0.2268 0.2268 5.7814 5.7814 5.7814 5.7814 0 0 0 0 2.0167 0.033611 97.081 96.795 98.079 97.318 7.1437 7.1419 7.1533 7.1463 1.0022 0.3888 0.3888 0.3888 0.3888 5.5822 5.6066 5.5281 5.5723 0 0 0 0 4.0181 0.066968 97.308 97.221 97.494 97.341 7.1432 7.1404 7.1493 7.1443 2.019 0.648 0.684 0.648 0.66 4.8773 4.7999 4.7839 4.8204 0.1385 0.1235 0.1302 0.13073 6.0245 0.10041 97.855 97.322 98.725 97.967 7.143 7.1476 7.1544 7.1483 3.0364 1.152 1.152 1.152 1.152 3.8046 3.8166 2.4116 3.3443 0.2309 0.2066 0.4908 0.30943 8.0249 0.13375 97.88 97.83 98.239 97.983 7.1425 7.151 7.1519 7.1485 4.0271 1.872 1.8 1.8 1.824 2.2973 2.2808 2.3323 2.3035 0.3196 0.3562 0.3517 0.3425 10.033 0.16722 98.186 97.79 98.525 98.167 7.1375 7.1414 7.1472 7.142 5.0078 2.88 3.096 3.024 3 0 0 0 0 0.4614 0.4407 0.4475 0.44987 12.033 0.20056 97.945 98.183 98.139 98.089 7.1409 7.1454 7.1546 7.147 6.0765 2.88 2.808 2.952 2.88 NaN NaN NaN NaN NaN NaN NaN NaN 14.033 0.23389 97.819 97.924 98.216 97.986 7.142 7.1469 7.1535 7.1475 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 16.037 0.26729 97.274 97.864 98.266 97.801 7.1402 7.148 7.1533 7.1472 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 18.05 0.30083 97.123 98.062 97.506 97.564 7.1395 7.147 7.1457 7.1441 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 20.052 0.33419 97.303 97.832 98.004 97.713 7.1389 7.1457 7.1473 7.1439 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 22.057 0.36762 97.603 97.078 97.568 97.416 7.1275 7.1453 7.1441 7.139 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 24.067 0.40111 96.798 97.353 97.74 97.297 7.1311 7.1367 7.1431 7.1369 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 26.067 0.43444 96.964 97.436 97.395 97.265 7.1332 7.1354 7.1466 7.1384 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 28.072 0.46787 96.634 97.466 97.323 97.141 7.1336 7.1385 7.15 7.1407 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 30.083 0.50139 96.133 96.895 96.742 96.59 7.1266 7.1438 7.1486 7.1396 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
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
mean_glu = 167x1
5.7814 5.5723 4.8204 3.3443 2.3035 0 NaN NaN NaN NaN
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
glu_1
glu_1 = 167x1
5.7814 5.5822 4.8773 3.8046 2.2973 0 NaN NaN NaN NaN
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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 comentarios
Alexander
Alexander el 4 de Jun. de 2024
Ah I can see it now! That is totally the problem, it must have been a typo. Thank you very much!
Voss
Voss el 4 de Jun. de 2024
You're welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Errorbars en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by