Message Boards Message Boards

Simplest way to interact with a 2D plot?

GROUPS:

Hi,

I'm quite new to Mathematica (I'm using v11) and I'm making the transition from MATLAB. There are many new and wonderful things in Mathematica but I've gotten stuck on something so basic I'm almost embarrassed to ask about it. The very first thing I tried was creating a 2D plot based on one of the examples:

ListPlot[Prime[Range[5000]]]

I'd like to pan and zoom this plot to explore the data. I found this question posed on the Mathematica StackExchange but all of the answers were surprisingly complex. I tried downloading one large chunk of code which claims to provide some generic 2D plot interaction but I don't think it's compatible with v11. I also found info in the Mathematica docs about how to rotate, zoom & pan graphics but it seems to apply only to 3D plots.

So I'm wondering:

  • Is there a built-in way to interact with 2D plots?
  • If not, can I get some very general info on how people think about 2D plots in Mathematica? Coming from MATLAB I spent most of my time exploring 2D plots, so the lack of this feature is surprising given how amazingly full-featured the Mathematica environment seems to be otherwise (of course I'm just scratching the surface too).

Regards, Jeremy Todd

POSTED BY: Jeremy Todd
Answer
4 months ago

I am not sure this is what you want, but a starting point may be:

Manipulate[
 Style[ListPlot[Prime@Range[5000], ImageSize -> {l, c}], 
  Magnification -> m], {{l, 500}, 250, 1000}, {{c, 350}, 300, 
  1000}, {{m, 1}, 0.1, 10}]
POSTED BY: Valeriu Ungureanu
Answer
4 months ago

This functionality is not (yet) included. 'interactive exploration of graphics' is something that has been missing from Mathematica for a long time. There are certain codes (like the ones on StackExchange) that 'emulate' it by setting the PlotRange. For now, Mathematica is not really the right tool to do it for all plots and for all kinds of data. For some kinds of data it can be optimized and be done fast. If you have any plot you can always zoom in using Show:

Show[yourplot, PlotRange -> {{xmin,xmax},{ymin,ymax}}] 

You can make xmin et cetera be interactive using e.g. Manipulate. But you won't get the behavior of Matlab easily...

POSTED BY: Sander Huisman
Answer
4 months ago

Okay thanks! I just wanted to make sure I wasn't missing anything.

Jeremy

POSTED BY: Jeremy Todd
Answer
4 months ago

Group Abstract Group Abstract