plotting 2 time series with errorbars along double y axis

1 view (last 30 days)
Bhowmik.U
Bhowmik.U on 25 Sep 2021
Answered: Scott MacKenzie on 17 Oct 2021
I have 2 time series data with standard eror rof mean too i.e.
errorbar(t,y1,erb-y1) and errorbar(t,y2,erb-y2)
This is to be plotted like the figure, I tried the code but cannot activate secondary y axis.
My Matlab Version is 2015
I need something like the enclosed figure
I tried something but didnt work out
errorbar(A(:,4),A(:,2), A(:,3),'Linestyle',':','LineWidth',1.5,'Color',[0 0 0])
axes1 = axes('Position',[0.131398601398601 0.11 0.775 0.815],...
'YTickLabel',{'','0','5','10','15','20','25'},...
'YTick',[-5 0 5 10 15 20 25]);
hold(axes1,'on');
% Activate the left side of the axes
% % yyaxis(axes1,'left');
% Create multiple error bars using matrix input to errorbar
errorbar(B(:,4),B(:,2),B(:,3),'LineWidth',1.5,'Color',[0 0 0]);
% Set the remaining axes properties
set(axes1,'YColor',[0 0 0],'YDir','normal');
ylim(axes1,[-1 30]);

Answers (1)

Scott MacKenzie
Scott MacKenzie on 17 Oct 2021
I think this is more-or-less what you are after, based on the figure posted:
% test data
x = 1:10;
A = [2 8 6 11 18 19 16 22 24 25];
B = [27 22 39 42 35 42 45 40 35 30];
Ae = 1+2*rand(1,10);
Be = 1+2*rand(1,10);
yyaxis left;
errorbar(x, A, Ae, Ae, 'color', 'b');
ylabel('A');
xlabel('Time');
yyaxis right;
errorbar(x, B, Be, Be, 'color', 'r');
ylabel('B');

Community Treasure Hunt

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

Start Hunting!

Translated by