MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg117312] Re: How to interactively re-scale graphics with mouse?
  • From: "Emilio Martin-Serrano" <emartinserrano at telefonica.net>
  • Date: Tue, 15 Mar 2011 06:02:19 -0500 (EST)

James, 

Are you using David Park's Presentations?

I have several notebooks  including the basics to pan and zoom, and modify
aspect ratio and plot range,  dynamically, on  2D graphics. It is based on
special Presentations features that save a lot of work, which in any case
might be  mimicked  with the standard locators plus some additional work to
implement the, eventually unavailable, Presentations functionality.

I use the trick to present some plots  with two frames in a row:  1) one
frame with the initial general plot, and 2) another frame to explore and
present focused areas of interest in the initial  plot. The changes in the
second plot and, if necessary, the overall aspect (as the reference plot) of
the first one, can be modified, undone and redone at will.

Tell me if you want me to send you a copy, but it needs Presentations to
run. In any case if, without presentations, you just load but not run the
notebook you could inspect its logic and (snapshots of) the produced
graphics.

E. Martin-Serrano 

-----Mensaje original-----
De: Heike Gramberg [mailto:heike.gramberg at gmail.com] 
Enviado el: lunes, 14 de marzo de 2011 12:02
Para: mathgroup at smc.vnet.net
Asunto: [mg117306] Re: How to interactively re-scale graphics with mouse?

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[0],
       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[0], Rectangle[coord1, coord2]}]}]],
>   {{"MouseDown", 2} :> (coord1 = MousePosition[
>       "Graphics"]), {"MouseUp", 2} :>
>     (Null; coord2 = MousePosition["Graphics"]; )},
>   {"MouseDragged", 2} :>
>    (Null; coord2 = MousePosition["Graphics"])]]
>



  • Prev by Date: Re: Joining points of ListPlot
  • Next by Date: Manipulating vectors with Position
  • Previous by thread: Re: How to interactively re-scale graphics with mouse?
  • Next by thread: Vectorized molecular dynamics with Mathematica?