How to update plot with EventHandler without using Print

Consider the following code:

plot = Plot[x^2, {x, 0, 10}];
func[point_] := Total[point];
EventHandler[plot, {“MouseClicked” :> (selectedPoint =
MousePosition[“Graphics”]; func[selectedPoint];
{ss1, ss2} = selectedPoint; Print[{ss1, ss2}];
Print[Plot[func[selectedPoint]*t, {t, 0, (ss1 + ss2)}]])}]

It prints plot and when I click on it, it collects the coordinates of the mouse click in selectedPoint and then shows the graph of a function depending on this point.

The only problem I have is that, because of Print, a new plot is created everytime there is a click. What I would like is just the plot and the graph of the last clicked point (two plots in total). Also, I’d like it to be as light as possible (avoiding DynamicModule if possible) so that it does not take too much computer resource (this is part of a pretty long code).



1 Answer


plot = Plot[x^2, {x, 0, 10}, ImageSize -> 300, PlotLabel -> “Original”];
func[point_] := Total[point];

Row[{EventHandler[ plot, {“MouseClicked” :> (sp = MousePosition[“Graphics”])}],
Dynamic[Plot[func[sp]*t, {t, 0, Tr@sp}, ImageSize -> 300, PlotLabel -> sp]]}]



Don’t use GraphicsRow[ ]- It spoils the graphics coordinate system
– Dr. belisarius
Sep 23 ’15 at 15:51