How can I add error bars to a stacked plot?
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Arisha F
el 24 de Feb. de 2023
Comentada: Les Beckham
el 24 de Feb. de 2023
Trying to add errorbars to a stacked plot? Seems there's no way to do this which is a shame as I very much like the way a stacked plot presents the data by comparing 3 variables with distinctly different y-axes against my x variable.

figure()
s = stackedplot(dist, stack, "DisplayLabels", ylabels); % stacked plot
xlabel('Distance from Springhead (m)')
title('Carbonate Chemistry with Distance Downstream')
grid on
0 comentarios
Respuesta aceptada
Star Strider
el 24 de Feb. de 2023
x = 0:0.5:10;
y = randn(3,numel(x));
err = randn(3,numel(x))/5;
figure
tiledlayout(3,1)
nexttile
errorbar(x, y(1,:), err(1,:))
Ax = gca;
Ax.XAxis.Visible = 'off';
% axis('padded')
nexttile
errorbar(x, y(2,:), err(2,:))
Ax = gca;
Ax.XAxis.Visible = 'off';
axis('padded')
nexttile
errorbar(x, y(3,:), err(3,:))
Ax = gca;
xt = Ax.XTick;
Ax.XAxis.Visible = 'off';
% axis('padded')
hold on
plot(xlim, [1 1]*min(ylim), '-k')
plot([1;1]*xt, [zeros(size(xt)); ones(size(xt))*0.07*diff(ylim)]+min(ylim),'-k')
hold off
text(xt, ones(size(xt))*min(ylim), string(xt), 'Horiz','center', 'Vert','top')
.
3 comentarios
Les Beckham
el 24 de Feb. de 2023
Note that you can adjust the spacing between the "stacked" plots to tweak how it looks (experiment with it).
Also, you should use (or not use) axis('padded') on all three tiles.
x = 0:0.5:10;
y = randn(3,numel(x));
err = randn(3,numel(x))/5;
figure
tiledlayout(3,1, 'TileSpacing', 'tight') %<<< or 'compact' or 'none' (but 'none' looks bad here)
nexttile
errorbar(x, y(1,:), err(1,:))
Ax = gca;
Ax.XAxis.Visible = 'off';
grid on
% axis('padded')
nexttile
errorbar(x, y(2,:), err(2,:))
Ax = gca;
Ax.XAxis.Visible = 'off';
% axis('padded')
grid on
nexttile
errorbar(x, y(3,:), err(3,:))
Ax = gca;
xt = Ax.XTick;
Ax.XAxis.Visible = 'off';
% axis('padded')
hold on
plot(xlim, [1 1]*min(ylim), '-k')
plot([1;1]*xt, [zeros(size(xt)); ones(size(xt))*0.07*diff(ylim)]+min(ylim),'-k')
hold off
text(xt, ones(size(xt))*min(ylim), string(xt), 'Horiz','center', 'Vert','top')
grid on
Más respuestas (0)
Ver también
Categorías
Más información sobre Errorbars en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

