5
$\begingroup$

I'm using ListPlot to label a sequence of ordered pairs in $[-1,1] \times [-1,1]$:

enter image description here

Question: How can I make these points show up as images (from the web, etc) instead of as blue dots? I'd like to keep the "Callout" labels if possible, but it's not strictly necessary.

$\endgroup$
  • 2
    $\begingroup$ Just use PlotMarkers like you normally would. There are examples in the documentation for PlotMarkers where they use images. $\endgroup$ – C. E. Jul 12 at 18:00
4
$\begingroup$

Using PlotMarkers as @C.E. suggested and images from @kglr

images = Rasterize[ExampleData[{"TestImage", #}], 
    RasterSize -> 200, ImageSize -> 30]&/@ {"Lena","Apples"};

ListPlot[{{Callout[{0.8, 0.8}, "A", Above]}, {Callout[{-0.8, -0.8}, 
    "B", Above]}}, Frame -> True, PlotMarkers -> images, 
 PlotRange -> {{-1.25, 1.25}, {-1.25, 1.25}}]

enter image description here

$\endgroup$
4
$\begingroup$
data = {{1, 1}, {4, 4}};
labels = {"A","B"};
images = Rasterize[ExampleData[{"TestImage", #}], 
    RasterSize -> 200, ImageSize -> 30]&/@ {"Lena","Apples"};

Using images as plot markers (as in Rohit's answer) is the most straightforward approach. Here are a few additional ways:

ListPlot with nested Callouts:

You can use the image as one of multiple call-outs for each data point:

data2 = MapThread[Callout[Callout[#, #3, Automatic, 1, 
      LeaderSize -> {{40, 45 Degree, 20}, 20}, Appearance -> "Leader"], #2, Center] &, 
    {data, images, labels}];

ListPlot[data2,  Frame -> True, Axes -> False, PlotRangePadding -> 2]

enter image description here

ListPlot + Callout + Labeled:

You can use Labeled to inject the image as a label:

data3 = MapThread[{Callout[Labeled[#, #2, Center], #3, Automatic, 1, 
        LeaderSize -> {{40, 45 Degree, 20}, 20}, Appearance -> "Leader"]} &, 
     {data, images, labels}];

ListPlot[data3,  Frame -> True, Axes -> False, PlotRangePadding -> 2]

enter image description here

BubbleChart + ChartElements:

BubbleChart[Append[#, 1]& /@ data,
  ChartElements -> images,
  ChartLabels -> Callout[labels, Above], 
  PlotRangePadding -> 1]

enter image description here

$\endgroup$
  • $\begingroup$ What are the advantages to this approach? $\endgroup$ – George Jul 12 at 19:20
  • $\begingroup$ @George, the only important advantage I can think of is you can inject additional information into visualization using the third components of input data (taken as 1 for both data points in the example) that control the relative bubble sizes. $\endgroup$ – kglr Jul 12 at 19:29

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.