2

I would like to layover a graph ontop of a figure but I need specific points in the graph to correspond with specific points in the figure.

I know that I can import the figure using

fig=Import["filename.ext","Graphics"];

and I create my plot using graphics:

p=Plot[Graphics[Points[data]]];

I think I need to overlay the plot on the figure by writing

Show[{fig,p}]

However I would like to control the size of the resulting figure without using the mouse and similarly be able to align the two graphics's.

Any pointers to the commands that are needed for this would be greatly appreciated.

Yossi Farjoun
  • 2,180
  • 3
  • 17
  • 25

2 Answers2

5

Instead of Show[] use Overlay[] and the Alignment option:

Overlay[{fig, p}, Alignment -> {-0.75, 0.33}] (* x,y values in [-1,1] *)

You can control the size of both Plot and Overlay individually by using the ImageSize option in either of both of them. And remember that you gan get the image size of the graphic you are importing via Import["filename.ext", "ImageSize"]. So to make sure that the plot is the same size as the image you could do:

size = Import["filename.ext", "ImageSize"];
p = Plot[Graphics[Points[data]], ImageSize->size];
Timo
  • 4,246
  • 6
  • 29
  • 42
0

The following will put bottom left corner of Image "img" at position 0,0 of the enclosing Graphics and scale it so that its longest side is 1 in Graphics coordinates.

Show[plot, Graphics[Inset[img, {0, 0}, {0, 0}, 1]]]

If you know where you want to put your image in terms of Graphics coordinates, you are done. If you want to put it at some point in terms of absolute coordinates you have to translate it into Graphics coordinates first, and that means finding coordinates system of your Graphics (PlotRange and PlotRangePadding) and coordinate system of the rendered image (ImageSize and ImagePadding) and figuring out the mapping.

I had to solve a similar problem earlier and with these options manually set, positioning worked as expected.

Community
  • 1
  • 1
Yaroslav Bulatov
  • 57,332
  • 22
  • 139
  • 197