Message Boards Message Boards

0
|
8508 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

How to align overlays of plots and images?

Hello,

I have an image of a 2D plot (data of y versus x) copied from a PDF file and stored in TIFF format. I used some simple image manipulation to read the scales of the axes (in pixels), define some scale transformations, and read the numbers in the graph. That worked fine and now I have a rather long list (~ 60K) of x-y data points.

Now I want to overlay the original image and a ListPlot of the data. I can make the original image semitransparent with SetAlphaChannel and adjust its size with ImageResize, but I have difficulties controlling the relative sizing and aligning of the image and the ListPlot, so as to get the axes to match exactly (I am OK with adjusting the parameters by trial and error).

I have tried Overlay, Prolog, Epilog, Inset, ImageCompose, but there is always some part of the sizing or aligning that does not respond as expected. There is obviously something I am missing. I have done this in Excel before, and it was not very hard (but it is hard with 60K data points).

Any ideas will be greatly appreciated.

OL.

POSTED BY: Otto Linsuain

I thought it may be of some use if I shared how I finally made this work. I used something like:

ListPlot[data, ImageSize -> lx, AspectRatio -> ly/lx, 
 PlotStyle -> Opacity[0.5], 
 Epilog -> 
  Inset[SetAlphaChannel[img, 0.4], {xpos, ypos}, {xpos0, ypos0}, 
   size]]

The aspect ratio is key. You need to adjust lx and ly to match size (depending on the aspect ratio of the original image, which you of course could also adjust with ImageResize), but this matching is not always straight-forward. In my case, (lx, ly) of (800, 534) matched size of 86.5, where the pixel size of img was (1691, 1127). Notice that one is trying to match specific features of the images (the axes), rather than the whole image, so the aspect ratios may not match exactly (depending, for example, on the font size used for the tick labels, plot labels, etc., both in the ListPlot and in the original image). In this case the axes took almost the entire image in img.

When you increase lx a bit, the result may be that the height decreases, rather than an increase in width. That makes the search for a match quite challenging. The positioning arguments are easier to adjust and are somewhat redundant. I think the documentation says the you are placing xpos in img at position xpos0 in the plot. They need to be re-adjusted each time you change lx, ly, or size.

Basically, it worked at the end, but it seems quite clumsy. There should be an easier way. I could not do it with ImageCompose or Overlay.

Best,

OL.

POSTED BY: Otto Linsuain
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract