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
.
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.
-
$\begingroup$ If you really want the output to be
Graphics
with all of its parts modifiable, I'd suggest usingInset
instead ofOverlay
. $\endgroup$– JensJun 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$– andre314Jun 22, 2013 at 18:50 -
$\begingroup$ @andre Thanks, that does make it more flexible. $\endgroup$– JensJun 22, 2013 at 21:22
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:
Pressing "x":
Pressing "x" again:
Rasterize
it first. $\endgroup$Show
. $\endgroup$drawing tool
does not work withshow
too! :( $\endgroup$