YY axis scale on plotyy

10 views (last 30 days)
hi everyone,
I am using the function plotyy in order to display dynamic of two different temperatures. Since it's two quantities in °C, I want the scales to be the same on each axis and the zero at the same level. I know wery well that I could plot the two dynamic on the same y-axis but I really want it on two different axis ! Here is the code :
% dynamique TA et TS5
figure (d); [AX,H1,H2]=plotyy(meteo.data(:,Idxdate_meteo),meteo.data(:,Idx_TA),meteo.data(:,Idxdate_meteo),meteo.data(:,Idx_TS5),'plot');
set(AX,{'ycolor'},{[0.1765 0.5294 0.9116];[0.1725 0.4353 0.1098]},'FontSize',14)
set(H1,'color',[0.1765 0.5294 0.9116])
set(H2,'color',[0.1725 0.4353 0.1098])
set(get(AX(1),'Ylabel'),'String','Tair [°C]','FontSize',20)
set(get(AX(2),'Ylabel'),'String','Tsol à 5cm [°C]','FontSize',20)
%aligner les zeros
maxval = cellfun(@(X) max(abs(X)), get([H1 H2], 'YData'));
ylim = [-maxval, maxval] * 1.1; % Mult by 1.1 to pad out a bit
set(AX(1), 'YLim', ylim(1,:) );
set(AX(2), 'YLim', ylim(2,:) );
And here is what I get :
X-axis doesn't need to change. I guess I have to use the axis function but I dont know how to use it to change scales of the both y-axis only. For example I want the both y-axis scales with min = -5°C and max = 50°C.
Thank you for your time, Louis

Accepted Answer

Giorgos Papakonstantinou
Giorgos Papakonstantinou on 17 Feb 2015
Try to use
linkaxes(AX, 'xy')
  1 Comment
Louis Deslée
Louis Deslée on 17 Feb 2015
Thank you very much, it is what I needed !!!
Have a nice day, louis

Sign in to comment.

More Answers (0)


Find more on Two y-axis 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!