I've got this picture:


The image has a resolution of 2001x2001. The left most pixel has an x-value of -2, and the right most pixel has an x-value of 2. Same goes for the y-values. Now I am trying to load this image into Mathematica and get it on the right scale inside a graphics environment. I've tried using inset like this:

julia = Import["https://i.stack.imgur.com/NLMXG.png"];
Graphics[{Blue, Rectangle[{-2, -2}, {2, 2}], 
    Inset[julia, Center, Center, 4]}, PlotRange -> {{-3, 3}, {-3, 3}}, 
  Axes -> True, AxesStyle -> Orange]

This still gives a little blue border around some sides, giving me the impression that it is not centered properly. Is there a better way to do this?

  • 1
    $\begingroup$ I changed Julia to julia. It's a good habit to avoid starting variable names with capital letters :) $\endgroup$
    – Öskå
    Jun 16, 2014 at 13:48

1 Answer 1


Inset is not suitable for reliable and precise positioning. Use Raster to include bitmap data in an image. It lets you specify the coordinates of the corners:

 Raster[ImageData[julia], {{-2, -2}, {2, 2}}],
 Frame -> True,
 GridLines -> Automatic,
 Method -> {"GridLinesInFront" -> True}

enter image description here

Note: the Graphics Method option I used is undocumented, so it might change in the future. It is used by functions like DensityPlot to make sure the grid lines are not obscured by other graphics elements.

  • $\begingroup$ @Öskå What version do you have? I tried with 8 and 9. $\endgroup$
    – Szabolcs
    Jun 16, 2014 at 14:30
  • $\begingroup$ @Öskå So is that the leftmost pixel or the leftmost black pixel? $\endgroup$
    – Szabolcs
    Jun 16, 2014 at 14:35

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.