Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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[""];
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?

share|improve this question
I changed Julia to julia. It's a good habit to avoid starting variable names with capital letters :) – Öskå Jun 16 '14 at 13:48
up vote 3 down vote accepted

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.

share|improve this answer
@Öskå What version do you have? I tried with 8 and 9. – Szabolcs Jun 16 '14 at 14:30
@Öskå So is that the leftmost pixel or the leftmost black pixel? – Szabolcs Jun 16 '14 at 14:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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