When creating subplots with Y-axes on both left and right side (without using the PLOTYY function), the right hand side axes do not align. For example:
x1 = 1:100; y1 = x1*ones(length(x1)); x2 = 1:100; y2 = cos(pi*x2/6); subplot(2,2,1) plot(x1,y1,'Color','r');set(gca,'XColor','r','YColor','r');axes('Position',get(gca,'Position'),... 'XAxisLocation','top',... 'YAxisLocation','right',... 'Color','none',... 'XColor','k','YColor','k');hold on;plot(x2,y2,'Color','k');subplot(2,2,2)plot(x1,y1,'Color','r');set(gca,'XColor','r','YColor','r');axes('Position',get(gca,'Position'),... 'XAxisLocation','top',... 'YAxisLocation','right',... 'Color','none',... 'XColor','k','YColor','k');hold on;plot(x2,y2,'Color','k');subplot(2,2,3)plot(x1,y1,'Color','r');set(gca,'XColor','r','YColor','r');axes('Position',get(gca,'Position'),... 'XAxisLocation','top',... 'YAxisLocation','right',... 'Color','none',... 'XColor','k','YColor','k');hold on;plot(x2,y2,'Color','k');subplot(2,2,4)plot(x1,y1,'Color','r');set(gca,'XColor','r','YColor','r');axes('Position',get(gca,'Position'),... 'XAxisLocation','top',... 'YAxisLocation','right',... 'Color','none',... 'XColor','k','YColor','k');hold on;plot(x2,y2,'Color','k');
If you enlarge the figure you will note that the axes on the right hand side of each subplot. They should lie exactly one over another; in this case, they do not align.
Best Answer