5
$\begingroup$

This question already has an answer here:

My googling efforts returned nothing so I thought I'd ask here. I often make a ListPlot[] with a huge array, and sometimes it has smaller features that I'd like to take a closer look at, but aren't very visible zoomed all the way out. Obviously I can just change the parameter PlotRange, but that's kind of cumbersome. Ideally, I'd like to be able to select a box around the part I want to zoom in on, and even more ideally maybe use my mousewheel to zoom in on where the cursor is, and be able to "grab" the plot to shift around where I'm looking at, when I'm zoomed in.

Most programs that plot things have this functionality, so I'm guessing MM must too. It seems like I might be able to do something similar using Manipulate cleverly (like, at least make sliders to control the zoom and center), but I don't see how to do it easily.

Is there any way?

$\endgroup$

marked as duplicate by MarcoB, m_goldberg, user9660, Kuba, Alexey Popkov Jun 14 '16 at 11:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ Probably you could include in your question the code of your current effort to use Manipulate on ListPlot ? $\endgroup$ – rhermans Sep 9 '14 at 15:10
  • $\begingroup$ @rhermans, it was just speculation or a guess, I haven't tried that. Maybe the solution to what I want requires it, but I'm really asking if there's just kind of a built in module. $\endgroup$ – YungHummmma Sep 9 '14 at 15:16
  • 1
    $\begingroup$ See for example this and other posts that appear if you search for "zoom." $\endgroup$ – C. E. Sep 9 '14 at 15:30
  • 1
    $\begingroup$ @Pickett, thanks, that's what I meant by using Manipulate. But that's clearly a workaround. Does MM really not have this kind of functionality built in? $\endgroup$ – YungHummmma Sep 9 '14 at 16:04
  • 1
    $\begingroup$ @YungHummmma I'm afraid not, not that I'm aware of anyway. $\endgroup$ – C. E. Sep 9 '14 at 16:47
4
$\begingroup$

The following will do what you ask, but likely not as expediently as you hoped for.

SeedRandom[42];
With[{data = RandomInteger[100, 100]},
  With[{xspan = Length@data, yspan = Max@data},
    DynamicModule[{mag, center, box, plotCenter},
      Column[{
        ClickPane[
          Dynamic @ ListPlot[data,
            PlotRange -> box[center],
            Frame -> True,
            Axes -> False,
            ImageSize -> Medium],
          (center = ##) &],
        Dynamic @ Style[Row[{"Manificaton: ", mag, "  Centered at: ", center}], "SR"],
        Dynamic @ ActionMenu["Magnification",
          {1 :> (mag = 1; center = plotCenter),
           1.5 :> (mag = 1.5),
           2 :> (mag = 2)}]
      }, Center],
      Initialization :> (
        mag = 1;
        plotCenter = .5 {xspan, yspan};
        center = plotCenter;
        box[center_] := 
          With[{x = center[[1]], y = center[[2]], dx = .5 xspan/mag, dy = .5 yspan/mag}, 
            {{x - dx, x + dx}, {y - dy, y + dy}}]
     )]]]

Clicking in the plot frame with center the plot at the point clicked on in the frame. Choosing a magnification value from the action menu will magnify the plot around the centered point.

full-plot

manified-plot

pan-zoom

$\endgroup$

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