1
$\begingroup$

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)}]])}]
Dynamic[MousePosition["Graphics"]]

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).

$\endgroup$
4
$\begingroup$
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]]}]
Dynamic[MousePosition["Graphics"]]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Don't use GraphicsRow[ ]- It spoils the graphics coordinate system $\endgroup$ – Dr. belisarius Sep 23 '15 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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