Message Boards Message Boards

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

How to align overlays of plots and images?

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