5
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ You can Rasterize it first. $\endgroup$
    – Kuba
    Jun 22, 2013 at 18:14
  • $\begingroup$ In case you're not aware, there is also Show. $\endgroup$
    – amr
    Jun 22, 2013 at 20:06
  • $\begingroup$ @amr: It seems that the drawing tool does not work with show too! :( $\endgroup$ May 18, 2017 at 21:13

2 Answers 2

5
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ If you really want the output to be Graphics with all of its parts modifiable, I'd suggest using Inset instead of Overlay. $\endgroup$
    – Jens
    Jun 22, 2013 at 18:26
  • 4
    $\begingroup$ 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. $\endgroup$
    – andre314
    Jun 22, 2013 at 18:50
  • $\begingroup$ @andre Thanks, that does make it more flexible. $\endgroup$
    – Jens
    Jun 22, 2013 at 21:22
1
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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