6
$\begingroup$

I have an external data file data which contains the position of stars of a galaxy simulations and it looks like this

data = Import["NGC_1566.out", "Table"];
L0 = ListPlot[data, Frame -> True, Axes -> False, 
     PlotStyle -> {Darker[Green], PointSize[0.001]}, 
     PlotRange -> {{-60, 60}, {-60, 60}}, AspectRatio -> 1]

enter image description here

and here is a real image of the NGC 1566

enter image description here

Now I would like to plot and fit my data on top of the real image. Any suggestions?

$\endgroup$
2
  • 1
    $\begingroup$ ImageCompose and some adjustments to the size and aspectratio of your plot should get you there. $\endgroup$
    – Karsten7
    Aug 4, 2014 at 15:03
  • $\begingroup$ @Karsten7. Great thanks! BTW, could you elaborate a little bit more your suggestions in a short answer, so I could accept it? $\endgroup$
    – Vaggelis_Z
    Aug 4, 2014 at 15:15

3 Answers 3

8
$\begingroup$

With the image of your plot

graph = With[{grImp = Import["https://i.stack.imgur.com/KffdP.jpg"]},
            ColorReplace[grImp, First@DominantColors@grImp -> Transparent]
            ];

and the image

img = Import["https://i.stack.imgur.com/3WFIL.jpg"];

One can prepare a composition interactively using

Manipulate[Module[{irGra},
  irGra = ImageResize[graph, {s1, s2}];
  ImageCompose[img, irGra, Scaled[{p1, p2}]]
  ],
 {{p1, 0.448}, 0.3, 0.8}, {{p2, 0.495}, 0.3, 0.8}, {{s1, 347.5}, 200, 500}, {{s2, 298.}, 200, 500}
 ]

ImageComposition

$\endgroup$
3
  • $\begingroup$ ImageCorrelate like, e.g. in the answers to this question, could be used to find the correct position. $\endgroup$
    – Karsten7
    Aug 4, 2014 at 15:56
  • $\begingroup$ Just a minor question: at the end, how can I export the joined plot in a .jpg format without showing the Manipulation controls? $\endgroup$
    – Vaggelis_Z
    Aug 4, 2014 at 16:17
  • 1
    $\begingroup$ @Vaggelis_Z Right click -> Save Image As... . If you want to use the composed image later in your notebook, e.g. for Export, than you can simply Set (=) it to a global symbol inside of Manipulate, e.g. ic = ImageCompose[img, irGra, Scaled[{p1, p2}]]. $\endgroup$
    – Karsten7
    Aug 4, 2014 at 16:48
5
$\begingroup$

One more way will be to use Prolog option with ListPlot. In that case we can use your image as a texture in the background too!

image = Import["https://i.stack.imgur.com/3WFIL.jpg"];
plotRange={{-60, 60}, {-60, 60}};
bdbox = Flatten[MapAt[Reverse, Outer[List, ##], 2], 1] & @@ plotRange;
back = {Texture[image], EdgeForm[],Polygon[bdbox, 
VertexTextureCoordinates -> {{1/5.5, 1/5.5}, {1/5.5,4.4/5.5},
{4.4/5.5, 4.4/5.5}, {4.4/5.5, 1/5.5}}]};

Then we can call your ListPlot. You can play with the VertexTextureCoordinates using Manipulate for example to hit the right zoom you need. I set the numbers above from my visual judgement only.

data = Import["NGC_1566.out", "Table"];
L0 = ListPlot[data, Frame -> True, FrameStyle -> Darker[Green],Axes -> False,
PlotStyle -> {Darker[Green], PointSize[0.001]},PlotRange ->plotRange,
AspectRatio -> 1,ImageSize -> 600, Prolog -> back, PlotRangeClipping -> False]

enter image description here

$\endgroup$
3
$\begingroup$

Not an excellent fit, but close:

L0 = ListPlot[data, Frame->True, Axes->False, PlotStyle -> {Darker[Green],PointSize[0.001]},
  PlotRange -> 1.9 * {{-60,60},{-60,60}}, AspectRatio -> 1]

and, with im as the JPEG :

ImageCompose[im, L0, {270, 290}]

but the credit goes to Karsten, not me!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.