I can't seem to get linkaxis to work (code is below, with small datasets attached). I am trying to get the subplots to line up, such that visually the x-axis is has the same range and width for both subplots.
Here is my code:
ax1 = subplot(2,1,1);scatter(x1, y1)box ongrid onaxis equalxlims = get(gca, 'XLim')ax = gca;ax.XRuler.Exponent = 0;ax.YRuler.Exponent = 0;xlims = get(gca, 'XLim')ax2 = subplot(2,1,2);scatter(x1, y1)xlim(xlims)box ongrid onax = gca;ax.XRuler.Exponent = 0;linkaxes([ax1,ax2],'x')
And here is what the figure looks like:
I also tried:
% adding this to the first subplot:
xlims = get(gca, 'XLim')positioning = get(gca,'position');% adding this to the second subplot:
xlim(xlims)set(gca, 'position', [positioning(1) positioning(2)/5 positioning(3) positioning(4)]) %x y width height
Best Answer