Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I combined two plots using Overlay. In the output plot I want to add few modifications. Usually I right click on the plot (for Plot or ListPlot) and use the drawing tool option. But there is no such option for the output of the Overlay. Is there any alternative to drawing tool to modify (like adding text or arrow) a plot created by Overlay.

share|improve this question
    
You can Rasterize it first. –  Kuba Jun 22 '13 at 18:14
    
In case you're not aware, there is also Show. –  amr Jun 22 '13 at 20:06
add comment

2 Answers

There is a three-argument form of Overlay that allows you to specify one of the layers as the target for interactions. So if you only want to modify the contents of the last layer in the list of overlays, you can specify that layer as follows:

Overlay[{Plot[1, {x, -1, 1}], 
  Graphics[{Blue, Circle[]}]}, Automatic, 2]

This draws a blue circle as an overlay, and lets you subsequently move that circle around with the drawing tools. Here, the argument 2 refers to the second layer with the circle. If you replace it by 1 you'll be able to modify the Plot instead. Unfortunately you can't get both to be interactive at the same time.

share|improve this answer
    
If you really want the output to be Graphics with all of its parts modifiable, I'd suggest using Inset instead of Overlay. –  Jens Jun 22 '13 at 18:26
3  
You can make the third argument of Overlay dynamical, for example Overlay[...Dynamic[x]], and by setting x=1 or x=2 edit the layer of your choice. –  andre Jun 22 '13 at 18:50
    
@andre Thanks, that does make it more flexible. –  Jens Jun 22 '13 at 21:22
add comment

This is a very rudimentary approach for an editing application. I'll reuse the Plot from Jens here...

Basically it shows you how to select a specific layer in your Overlay graphical object through a specific event (Right-Mouseclick for instance). You can handle this specific event to flip through the Overlay layers. From there you could do your specific manipulations with the drawing tools.

DynamicModule[{x = 1}, 
    EventHandler[
       Overlay[{Plot[1, {x, -1, 1}], Graphics[{Blue, Circle[]}]}, Automatic, 
       Dynamic[x]], {{"KeyDown", "x"} :> (x = x /. {1 -> 2, 2 -> 1})}]]

I've chosen here KeyDown as my event, since mouse clicks (like right mouse clicks) are already heavily overloaded and this is getting a nightmare to proper pass the events to the built-in event handlers.

The plot:

enter image description here

Pressing "x":

enter image description here

Pressing "x" again:

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

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.