       Re: How to interactively re-scale graphics with mouse?

• To: mathgroup at smc.vnet.net
• Subject: [mg117306] Re: How to interactively re-scale graphics with mouse?
• From: Heike Gramberg <heike.gramberg at gmail.com>
• Date: Mon, 14 Mar 2011 06:02:02 -0500 (EST)

```I don't know about a standard way to do this, but I think that all you need to do in your code below is use a dynamic variable for your PlotRange and update that when a MouseUp event occurs, i.e.

DynamicModule[{coord1 = {0, 1}, coord2 = {0, 1},
pltrange = {{1, 4}, {0.01, 0.3}}},
EventHandler[
Dynamic[Show[{Plot[{HopfF[0.05, j], TuringF[8, 0.05, j]}, {j, 1, 5},
PlotRange -> pltrange,
PlotStyle -> {{Thickness[0.001], Black}, {Thickness[0.002],
Red}}, Filling -> {{1 -> {{2}, {LightBlue,
LightGreen}}}, {1 -> {Axis, LightRed}}, {2 -> {Top,
LightYellow}}}, Frame -> True,
PlotLabel -> {coord1, coord2}],
Graphics[{EdgeForm[{Dashed, Red}], Red, Opacity,
Rectangle[coord1, coord2]}]}]], {{"MouseDown",
2} :> (coord1 = MousePosition["Graphics"]), {"MouseUp",
2} :> (Null; coord2 = MousePosition["Graphics"];
pltrange = Transpose[{coord1, coord2}])}, {"MouseDragged",
2} :> (Null; coord2 = MousePosition["Graphics"])]]

Heike.

On 13 Mar 2011, at 10:27, James wrote:

> Hello guys,
>
> I'd like to draw a plot in manipulate, then click the right mouse button, drag the mouse while a red bounding box shows the area, then when I release the button, the plot is redrawn with that bounding box.  Maybe there is a standard way to do this.  Could someone let me know if so?  Otherwise, I almost have it with a DynamicModule in the code below which captures the mouse locations and prints the coordinates as the title just for diagnostics, but I cannot figure out how to get the plot to redraw with those new coordinates and was hoping someone could look at it and give me some advise how to fix it. Thanks guys,
>
> \[Gamma]F[j_] := (j^2 - 1)/(j^2 + 1)^2;
>
> HopfF[TIn_, jIn_] := \[Gamma]F[jIn] - TIn;
>
> TuringF[DIn_, TIn_, jIn_] :=
>   DIn*(Sqrt[\[Gamma]F[jIn]] - Sqrt[TIn])^2;
>
> DynamicModule[{coord1 = {0, 1},
>   coord2 = {0, 1}}, EventHandler[
>   Dynamic[Show[{Plot[{HopfF[0.05, j],
>        TuringF[8, 0.05, j]}, {j, 1, 5},
>       PlotRange -> {{1, 4}, {0.01, 0.3}},
>       PlotStyle -> {{Thickness[0.001], Black},
>         {Thickness[0.002], Red}}, Filling ->
>        {{1 -> {{2}, {LightBlue, LightGreen}}},
>         {1 -> {Axis, LightRed}},
>         {2 -> {Top, LightYellow}}}, Frame -> True,
>       PlotLabel -> {coord1, coord2}],
>      Graphics[{EdgeForm[{Dashed, Red}], Red,
>        Opacity, Rectangle[coord1, coord2]}]}]],
>   {{"MouseDown", 2} :> (coord1 = MousePosition[
>       "Graphics"]), {"MouseUp", 2} :>
>     (Null; coord2 = MousePosition["Graphics"]; )},
>   {"MouseDragged", 2} :>
>    (Null; coord2 = MousePosition["Graphics"])]]
>

```

• Prev by Date: Re: Question on Unevaluated
• Next by Date: Re: Joining points of ListPlot
• Previous by thread: How to interactively re-scale graphics with mouse?
• Next by thread: Re: How to interactively re-scale graphics with mouse?