title: Plotyy right y-axis and associated data shifting upwards when enlarging the figure
body: <p>I used code similar to the <code>plotyy</code> function to plot two y variables. However, the righthand side of the graph containing the second y-axis shifts/moves when I alter the size of the figure. This also results in an upward shift in the y variable from the bottom x-axis. This doesn't happen with the left y-axis. How do I lock/prevent the right y-axis and its associated y variable from shifting upwards, away from the base of the x-axis?   </p>
  
  <pre><code>%Some code
  
  hFig=figure;
  
  %Line 1 (blue line variable)
  hl1 = line(x1,y1,'Color',deepskyblue,'LineStyle','-.');
  ax1 = gca;
  set(ax1,'LineStyle',line_style,'FontSize',axis_font,'XColor',x_color,'YColor',y_color);
  
  %Line 2 (black line variable)
  ax2 = axes('Position',get(ax1,'Position'),...
             'XAxisLocation','top',...
             'YAxisLocation','right',...
             'Color','none',...
             'XColor',x_color,'YColor',y_color);
  hl2 = line(x2,y2,'Color','k');
  set(ax2,'LineStyle',line_style,'FontSize',axis_font,'XColor',x_color,'YColor',y_color,'XTick',[]);
  linkaxes([ax1 ax2],'x'); %Links the two x axes
  
  %Save figure 
  set(hFig,'Units','inches','Position',[1 1 12 6]); %[x y width height]
  saveas = input('enter the filename to save as an image','s');
  print(saveas,'-dpng','-r300');
  </code></pre>
  
  <p>Original plot (Note: The original figure was saved manually in Matlab):
  <img src="https://i.stack.imgur.com/lbk3k.png" alt="before"></p>
  
  <p>After resize (Note: The after resize figure was saved using the code below. This is where we see a shift in the right y-axis):
  <img src="https://i.stack.imgur.com/EbpSL.png" alt="after"></p>