I have the following image (500*430pixels, 8bit, png): https://i.imgur.com/QVlIq3g.png

How can I show axes around (horizontal data: [1,15]; vertical data: [2,10])?

The result should be the following:

enter image description here

pic = Import["https://i.imgur.com/QVlIq3g.png"];

 Inset[pic, Scaled[{.5, .5}], Automatic, Scaled[1]],
 Frame -> True,
 PlotRange -> {{1, 15}, {2, 10}},
 AspectRatio -> ImageAspectRatio@pic

enter image description here

  • $\begingroup$ Great, thank you ... $\endgroup$ – mrz Nov 16 '16 at 16:00

I wrote you a function for this. It works by explicit setting the option FrameTicks.


Which can simply be called with:




Your Labels can simply be introduced by calling to Show and setting FrameLabel:

Show[ShowImageWithTicks[img,Range[1,15,2],Range[2,10]],FrameLabel->{"time [s]","x [mm]"}]


  • $\begingroup$ You're using a Show inside of a Show. Why not combine it to be more elegant? $\endgroup$ – corey979 Nov 16 '16 at 15:42
  • $\begingroup$ Because its not a complex task to set FrameLabel so i didn't saw the reason to do it. If OP wants to, i'll combine it into a single function with optional parameters. $\endgroup$ – Julien Kluge Nov 16 '16 at 15:47

Assume, im is your image. Try this:

f[x_] := {(600 x)/8 - 150, x}
g[x_] := {(600*x)/(14), x}; 

    Show[im, Frame -> True, FrameTicks -> {{f[#] & /@ Range[2, 10, 2], None},
        {g[#] & /@ Range[2, 14, 2], None}}]

enter image description here

Have fun!

  • $\begingroup$ Thank you ... now I understand how to use FrameTicks ... $\endgroup$ – mrz Nov 18 '16 at 13:18

One possibility, use Show and turn the axes on with Axes->True. A rather crude solution for the ticks would be to scale them as follows (but there are surely more elegant solutions):

tx = Table[{500*i, 15*i}, {i, 0, 1, 1/15}];
ty = Table[{430*i, 10*i}, {i, 0, 1, 1/10}];
Show[img, Axes -> True, AxesLabel -> {"time (sec)", "x (mm)"}, 
 Ticks -> {tx, ty}]

enter image description here

  • $\begingroup$ Thanks ... I would like to have different axes values than the pixel numbers (see above). $\endgroup$ – mrz Nov 16 '16 at 15:04
img = Import["https://i.imgur.com/QVlIq3g.png"];

id = ImageDimensions @ img

{500, 430}

ticks = {Transpose @ {Subdivide[0, id[[1]], 7], Subdivide[1, 15, 7]}, 
         Transpose @ {Subdivide[0, id[[2]], 4], Subdivide[2, 10, 4]}}

Labeled[Show[img, Axes -> True, Ticks -> ticks],
 {"time (s)", "x (mm)"}, {Bottom, Left}, RotateLabel -> True]

enter image description here

Using Frame is more straightforward, but I'm providing a different approach. Additionally, one can define pl = {{1, 15}, {2, 10}} and insert specific parts in ticks (as well as the number of subdivisions) to make it automated; I'll leave it as it is for clarity.


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.