1
$\begingroup$

I can use this code to label my points with text.

Show[
 NumberLinePlot[{1, 2, 3}],
 Graphics[Text["A", {1, 1}, {0, -1}]], 
 Graphics[Text["B", {2, 1}, {0, -1}]],
 Graphics[Text["C", {3, 1}, {0, -1}]]
 ]

But how do I use an image instead of text as a label? I don't see how to do this in the documentation and just adding an image in the Show function breaks everything (I assume its because we need to define its coordinates somehow).

$\endgroup$
  • $\begingroup$ Try Inset. P.s. you don't need separate Graphics for each element, you can gather them with {}. $\endgroup$ – Kuba Apr 1 '15 at 19:41
2
$\begingroup$
 im = Import["ExampleData/lena.tif"];

Show[
 NumberLinePlot[{1, 10, 20, 30, 40, 50}],
 Graphics[
  {Inset[im, {1, 1}],
   Inset[im, {20, 1}],
   Inset[im, {40, 1}]
   }
  ]
 ]

Mathematica graphics

You'd have to adjust the sizes and scale things to make it look ok

| improve this answer | |
$\endgroup$
2
$\begingroup$

Update: You can also add the images as metadata and use ListPlot with the options LabelingSize and LabelingFunction:

img = ExampleData[{"TestImage", "Mandrill"}];
pnts = {1, 10, 20, 30, 40, 50};

ListPlot[Thread[{pnts, 0}] -> ConstantArray[img, 6], 
 ImageSize -> 600, Axes -> {True, False}, 
 LabelingSize -> 50, 
 LabelingFunction -> ((Placed[#3[[3, 1]], {1/2, -1/5}] &)), 
 ImagePadding -> Scaled[.05], PlotRangeClipping -> False, 
 AspectRatio -> 1/3, PlotStyle -> PointSize[0], Ticks -> {pnts, None}]

enter image description here

Original answer:

You can also use Epilog:

img=ExampleData[{"TestImage", "Mandrill"}];
pnts={1, 10, 20, 30, 40, 50};

NumberLinePlot[pnts, ImageSize->600, 
 Epilog -> (Inset[Show@Thumbnail[img, 50], #]&/@ Thread[{pnts, 1}])]

enter image description here

Or post-process Point primitives into Insets:

NumberLinePlot[pnts, ImageSize->600]/. 
   Point[x_]:>(Inset[Show@Thumbnail[img,50], #] & /@{x})
(* same picture *)
| improve this answer | |
$\endgroup$

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