2
$\begingroup$

I have this plot:

enter image description here

which made by:

data27 = Import["~/Events/scan.dat"];
idata27 = Table[{data27[[i, 2]], data27[[i, 3]]*10^3}, {i, 1,Length[data27]}];
sh = Show[
  ListLogPlot[idata27, Axes -> True, Frame -> True, Joined -> True], 
  PlotRange -> {{150, 1300}, {Log[10], Log[10000]}}, ImageSize -> 600]

How stick this plot on an experimental figure like what follows, such that the (y,x) axes of the figure and the plot coincidence with each other ?

mm = Import["~/Desktop/search/CMS-PAS-HIG-16-002_Figure_007.png", 
  ImageSize -> 600]

enter image description here

I tried:

Overlay[{mm, sh}, Alignment -> {-0.4, -0.6}]

But I got:

enter image description here

The problem is that the plot now doesn't move at all in the X- axis if I changed Alignment -> {x, -0.6}. Also although the y- Axises coincidence both X- Axes are not the same .. any help ?

$\endgroup$
  • 1
    $\begingroup$ This requires manual positioning. I would not use Mathematica for this. If you want to use Mathematica anyway, you could try inserting that image into a Graphics using Raster, then combining with your plot using Show. Specify the coordinates manually in Raster. Adjust them until there's a good fit between the axes. See also here: mathematica.stackexchange.com/questions/1524/… $\endgroup$ – Szabolcs Sep 14 '16 at 13:59
  • $\begingroup$ I tried Raster but hopless, I couldn't make accurate as I want .. which tool can be used instead of Mathemtica if I want to make a plot with an experimental data ? $\endgroup$ – S.S. Sep 14 '16 at 14:50
3
$\begingroup$

You can do this with mathematica, but you might be better off using something else for some post processing. Here's a very cumbersome way to do this - if you have to do it more than once, I'd try to streamline the process but this will get you started.

First, figure out the aspect ratio on the original image. If you right click the image in MMA you can 'Get Coordinates'. I found the lower left and upper right corners to have coordinates: {48.2, 48.3},{448.8, 431.6} so the aspect ratio is: ar = #2/#1&@@({48.2, 48.3} - {448.8, 431.6}) which is about 0.96.

Then create your plot, which I'll do with fake data since I don't have access to your computer.

img = Import[...your data here...];

fakedata = 
  Table[{x, N@10^4*Exp[-(x - 500)^2/200^2]}, {x, 150, 1300}];
sh = ListLogPlot[
   fakedata
   , Axes -> True
   , Frame -> True
   , Joined -> True
   , PlotStyle -> Red
   , PlotRange -> {{150, 1300}, {10, 10^5}}
   , AspectRatio -> 0.96
   , ImageSize -> 600
   , Background -> None
   , ImagePadding ->None
   , FrameTicks -> None
   ];

I've done a few things, first the plot range should be the same as the plot you're going to overlay onto, make sure the aspect ratio is set as well, and get rid of padding. Also don't forget to get rid of the FrameTicks since your original plot will provide them.

Then for the placement and size I use Graphics with Inset and Rasterize on your image inside a manipulate. Notice that when you Rasterize you need to set Background->None. This is where you'll have to play around a little.

Manipulate[
 tempimage = Show[
   Graphics[{Inset[img, ImageScaled@{0, 0}, {Left, Bottom}, 
      ImageScaled@{1, 1}]}]
   , Graphics[Inset[
     Rasterize[sh, ImageSize -> 600, Background -> None]
     , ImageScaled@{pos, pos}, {Left, Bottom}, ImageScaled@{sx, sx}]
    ]
   ];
 Column[{
   tempimage
   , Button["Set Image", {finalImage = tempimage}]
   }
  ]
 , {sx, 0.5, 1}
 , {pos, 0, 1}
 ]

enter image description here

Once you get the right size and position, you can hit the Set Image button to assign the image to finalimage which you can then evaluate in another cell to make sure the image is the one you want. Which for this fake data is:

enter image description here

$\endgroup$
  • 1
    $\begingroup$ This is great, manyyyyyy thanx .. $\endgroup$ – S.S. Sep 14 '16 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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