3
votes

I'm using plotyy to plot two datasets with the same x values over two different y scales. It all works perfectly, until I try to change the limits of the x-axis. (Matlab plots a lot of extra space on both sides.) Whenever I add in 'set(AX(1) xlim', the lines associated with that axis disappear and the plot appears blank.

My code:

[AX,h1,h2]=plotyy(datenum(DateVector),data1,datenum(DateVector),data2);
dateFormat = 10;
datetick(AX(1),'x',dateFormat);  
datetick(AX(2),'x',dateFormat); 
set(AX(1),'XLim',[1950 2013]);  
set(AX(2),'xlim',[1950 2013]); 
xlabel('Year') 
ylabel('Data1');  
ylabel('Data2');

Thanks!

1

1 Answers

3
votes

Try this instead.

set(AX(1),'XLim',[datenum(1950,1,1) datenum(2013,1,1)]);  
set(AX(2),'Xlim',[datenum(1950,1,1) datenum(2013,1,1)]); 

Since your x-axis is date (years), the limits have to be specified in datenum format too.

Also, you need to give the axis handle to label functions too.

ylabel(AX(1),'Data1');  
ylabel(AX(2),'Data2');