MathGroup Archive 2008

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

Search the Archive

Re: Zoomable ListPlot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91895] Re: Zoomable ListPlot
  • From: Peter Steneteg <peter.steneteg at gmail.com>
  • Date: Fri, 12 Sep 2008 05:26:38 -0400 (EDT)
  • References: <gaaqu7$12a$1@smc.vnet.net>

On 11 Sep, 04:12, "peter.stene... at gmail.com"
<peter.stene... at gmail.com> wrote:
> Hi
>
> I made a small function to produce a zoomable listplot, hold alt down
> and draw a rect to zoom, shift click to return. I'm not very familiar
> with the eventhandlers, maybe someone else can do this much better,
> without redrawing the plot as many times? I would also like to be able
> to turn data series on and off by clicking the legend, but I have no
> idea on how to do that...
>
> /Peter

I found a way to turn data series on and off...

PListPlot[fun_,
  opts : OptionsPattern[{Options[ListPlot], Legend -> {""},
     Frame -> True, ColorScheme -> 1, PPlotStyle -> {}}]] :=
 DynamicModule[{p1, p2, pr = Automatic, pt = {{0, 0}, {0, 0}},
   pl = {}, mylegend, is, style, show, ps},
  show = Table[True, {i, 1, Length[fun]}];
  ps = Table[
    Directive[{ColorData[OptionValue[ColorScheme], i]}~Join~
      OptionValue[PPlotStyle]], {i, 1, Length[fun]}];
  mylegend[data_] := Framed[Grid[
     MapIndexed[{Item[
         Graphics[{ColorData[OptionValue[ColorScheme], First@#2],
           Thick, Line[{{0, 0}, {1, 0}}]}, AspectRatio -> .1,
          ImageSize -> 30], Alignment -> {Center, Bottom}],
        Button[Item[
          Style[#1, FontSize -> 16,
           FontColor -> If[show[[First@#2]], Black, Gray],
           FontFamily -> "Helvetica"], Alignment -> {Left, Top}],
         show[[First@#2]] = ! show[[First@#2]],
         Appearance -> Frameless, Alignment -> {Left, Top}]} &,
      data]], Background -> RGBColor[1, 1, 0.99999]];
  is[x_] := {x, x/GoldenRatio};
  EventHandler[
   Dynamic[
    ListPlot[
     fun[[ Select[MapIndexed[If[#1, First@#2] &, show], NumberQ]]],
     PlotRange -> pr,
     Epilog -> {pl,
       Inset[mylegend[OptionValue[Legend]],
        ImageScaled[{1 - 0.02, 1 - 0.02}], {Right, Top}]},
     Evaluate@ FilterRules[{opts}, Options[ListPlot]],
     PlotStyle ->
      ps[[ Select[MapIndexed[If[#1, First@#2] &, show], NumberQ]]],
     MaxPlotPoints -> ControlActive[1000, Infinity]],
    SynchronousUpdating -> Automatic],
   "MouseDown" :> (If[CurrentValue["AltKey"],
      p1 = MousePosition["Graphics"]];
     			If[CurrentValue["ShiftKey"], pr = Automatic];
     ),
   "MouseUp" :> (If[CurrentValue["AltKey"],
      p2 = MousePosition["Graphics"];
      pt[[1, 1]] = p1[[1]];
      pt[[1, 2]] = p2[[1]];
      pt[[2, 1]] = p1[[2]];
      pt[[2, 2]] = p2[[2]];
      pr = pt;
      pl = {};
      ]
     ),
   "MouseDragged" :> (If[CurrentValue["AltKey"],
       p2 = MousePosition["Graphics"];
       pt[[1, 1]] = p1[[1]];
       pt[[1, 2]] = p2[[1]];
       pt[[2, 1]] = p1[[2]];
       pt[[2, 2]] = p2[[2]];
       pl = {Line[{p1, {p2[[1]], p1[[2]]}, p2, {p1[[1]], p2[[2]]},
           p1}]};
       ];
     )
   ,
   PassEventsDown -> True
   ]
  ]


  • Prev by Date: Re: Alternating sums of large numbers
  • Next by Date: Re: Re: How to simplify ArcCos[x/Sqrt[x^2+y^2]] to Pi/2-ArcTan[x/Abs[y]]?
  • Previous by thread: Zoomable ListPlot
  • Next by thread: Alternating sums of large numbers