Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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 used Jens' legendmaker to Overlay graphics to get a nice legend on my ListPlot.

My question is if is there any way to make the output from Overlay behave like output from ListPlot in terms of the ability to zoom in to investigate, get co-ordinates, drawing tools, ability to right click on the graphic itself and save high resolution graphic as a host of things etc? I was able to right click the cell and save selection as a very low resolution jpeg.



boundaryplot = ListPlot[{H0SPlot, H0DPlot},PlotRange -> Full]
opts = Sequence[Background -> LightOrange, RoundingRadius -> 10];
labels = {"H0S", "H0D"}
Overlay[{boundaryplot, legendMaker[labels, opts]}, All, 1,Alignment -> {0.5, 0.5}]

While the Overlay options enable me to zoom in etc, when I right click on the image to save graphic as , I tried jpeg and pdf, it only saves the ListPlot and not the Legend. When I right click on the cell itself and use save selection as then I am able to save as jpeg something lower-res that also includes the legend.

share|improve this question
I wouldn't be surprised if the answer was no. Why not make all the resizings, annotations, etc. on the list plot first before doing the overlay? That seems to work very well. – R. M. Sep 24 '12 at 22:30
Have you looked at the second and third parameters to Overlay which let you specify which of the layers is interactable? – amr Sep 24 '12 at 22:34
@amr Excellent! You should write that as an answer. Changing the Overlay call to something like Overlay[{plot, legend}, All, 1, Alignment -> {Right, Top}] allows you to interact with the graphics as usual. – R. M. Sep 24 '12 at 22:46
... also see this related question on Overlay with multiple layers each with interactive content. – kglr Sep 25 '12 at 2:06
Thanks Amr and RM! The wolfram more information barely touched upon what the 2nd and 3rd arguments do. I still don't understand what the second argument does. If either of you write up an answer then I'd be happy to accept it. Kguler, thanks for the link. that was very helpful. I don't know what I didn't find that myself. I should look harder. – Amatya Sep 25 '12 at 2:20
up vote 3 down vote accepted

Overlay's second parameter specifies which layers are visible and in what order. The third parameter specifies which layer can be interacted with. For your usage you can use the Overlay[layers, All, 1] form.

Here's a small demonstration for Overlay. I got a little carried away <_< but it should make clear what the second parameter can be used for.

shapes = {{Blue, Disk[]}, {Red, Rectangle[]}, {Yellow, Polygon[{{-1, -1}, {0, 1}, {1, -1}}]}};

indices = Range[Length[shapes]];
visibleChoices = MapIndexed[#1 -> Row[Graphics[#, ImageSize -> 20] & /@ Part[shapes, #1]] &, Subsets[indices]];
interactableChoices = MapIndexed[#2[[1]] -> Graphics[#1, ImageSize -> 20] &, shapes];

 Column@{"Overlay arguments",
   Grid[{{Graphics[{Opacity[.7], #}, ImageSize -> 20] & /@ shapes,
      direction[visible], interactable}}, Frame -> All, FrameStyle -> Lighter[Gray, .7]],

   Overlay[Graphics[{Opacity[.7], #}] & /@ shapes,
    direction[visible], interactable, Alignment -> Center]},

 {{visible, indices}, visibleChoices},
 {{direction, Identity}, {Identity -> ascending, Reverse -> descending}},
 {{interactable, 0}, interactableChoices, ControlType -> SetterBar}]

Overlay demonstration

Note: I didn't worry about preserving the user's adjustments. I think that would involve messing with ImageSize and PlotRange or other stuff and it would have complicated the demonstration.

Although I only implemented ascending/descending order, the second parameter can be any permutation, meaning you can arbitrarily reorder the layers.

share|improve this answer
oh man! Thats such a cool demonstration! Thank you. – Amatya Sep 27 '12 at 5:38

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.