title: matlab plot graph of data over an image
body: <p>What I would like to do is plot an image of a graph (from say a pdf file or a scanned image).  Next, I would like to overlay an axis on the graph in the image, and then plot data on that axis (over the image).  </p>
  
  <p>Using imtool, I know the coordinates of the graph in the image (x range = ~52-355 pixels, and y range = 23(top) -  262(bottom) pixels in this case).</p>
  
  <p>This is what I have tried:</p>
  
  <pre><code>I = imread('C:\MATLAB\R2014a\help\images\ref\ftrans2_fig.png');
  I = squeeze(uint8(mean(I,3)));
  figure, imshow(I)
  [rows, cols] = size(I);
  x_data = (-1 : .01 : +1)';
  y_data = 1 - x_data.^2;
  h1 = axes('Position',([52, 23, 355-52, 262-23] ./ [cols, rows, cols, rows] ));
  set(h1, 'Color', 'none')
  hold on
  plot(x_data, y_data, '-rx')
  </code></pre>
  
  <p>Question:  Knowing the pixel coordinates of the graph in the image, how do I determine the proper position of the axis in the figure, (my code fails to account for the actual size of the figure box, the gray border around the image).  I have to do this for several images and sets of data, so I would like an automated method, assuming I find the coordinates of the graphs in the image ahead of time.</p>
  
  <p>Thanks for your reply!  (1st time posting, please be kind)</p>