Code covered by the BSD License  

Highlights from
INTERACTIVEMOUSE

5.0

5.0 | 10 ratings Rate this file 11 Downloads (last 30 days) File Size: 10 KB File ID: #10588
image thumbnail

INTERACTIVEMOUSE

by Jiro Doke

 

30 Mar 2006 (Updated 24 Apr 2006)

Interactively pan, zoom, center view a plot using the mouse

| Watch this File

File Information
Description

After I made this in R13 and testing it in R14, I noticed that the PAN function had a similar functionality. However, This function has additional features (zoom and center view)
#######################################

INTERACTIVEMOUSE toggles the interactive mode of the current figure.
INTERACTIVEMOUSE ON turns on the interactive mode.
INTERACTIVEMOUSE OFF turns off the interactive mode.
INTERACTIVEMOUSE RESET sets the 'restore point' to the current view.
INTERACTIVEMOUSE RESTORE restores the view to the 'restore point'. The 'restore point' is predefined as the original view, unless the current view is set as the 'restore point' with RESET.
INTERACTIVEMOUSE RESTORE_ORIG restores the view to the original view (the view before INTERACTIVEMOUSE was initially called on this figure). This 'restore point' is fixed regardless of whether RESET was called or not.

INTERACTIVEMOUSE(FIG) and INTERACTIVEMOUSE(FIG, OPTION) applies to the figure specified by handle FIG. FIG can be a vector of figure handles. OPTION can be any of the above arguments. The figure(s) can have multiple axes.

The following features are included in the interactive mode:
 Pan : click and drag.
 Zoom : right click (or CNTRL-click) and drag.
 Center View : double click.
 Reset View : <r> with the cursor over the axes region. This resets 'restore point'. (see above note about RESET option)
 Restore View : <space> with the cursor over the axes region. This restores to the 'restore point'. (see above note about RESTORE option)
 Help window : <h>
 Exit mode : <escape>

Note about Zoom Feature:
 (2D views) : the zoom ratio depends on the location of the pointer with respect to the initial click location. Pressing the <shift> key ONCE toggles the constrained mode. In CONSTRAINED mode, the zoom ratio is constrained along x-axis, y-axis, or xy-axes depending on the pointer location. The figure window title indicates that constraint mode is active. If the axes DataAspectRatioMode is MANUAL, the zoom will always be constrained to preserve the specified aspect ratio (PROPORTIONAL mode). This is for working with images.

 (3D views) : the zoom is always xyz-constrained (PROPORTIONAL). The aspect ratios are always preserved.

In the interactive mode, several figure and axes properties are set, but the current properties are restored when the interactive mode is exited. During interactive mode, the figure name changes to 'InteractiveMouse', and the figure is undocked (certain features don't work in docked mode). This works with 2D plots, images, and 3D plots (for the most part).

Examples:
% Interactively examine high frequency noise
  x=0:.001:10;
  y=sin(x)+.01*rand(size(x));
  plot(x,y)
  interactivemouse;

% Multiple axes
  load clown;
  subplot(211);image(X);colormap(map);axis image;
  subplot(212);plot(rand(100,1), '.-');
  interactivemouse;

% Use LINKAXES to link multiple axes. (>R13)
  ax(1)=subplot(211);plot(rand(100,1), 'r.-');
  ax(2)=subplot(212);plot(rand(100,1), '.-');
  linkaxes(ax);
  interactivemouse;

See also zoom, pan, linkaxes

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
view3d.m, Zoom Keys, drag.m, GRABIT

MATLAB release MATLAB 6.5 (R13)
Other requirements Also tested in R2006a
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (11)
07 Apr 2006 Don Riley

Worked nicely for me. Appears to have better performance than built in pan. Worked on a figure with two images and a figure with a imscrollpanel (from IPT), and in R2006a.

19 Mar 2007 Diego Barragán

Master

12 Apr 2007 Jennifer Horsman

I'm using 6.5 Rel 13. This tool works wonderfully. I am using it in a 3D plot (several planar surfaces crossing each other) and I am so glad it does not change the XYZ proportions when zooming in and out.

06 Aug 2007 Sachin Lohani

Works like magic...great job!

29 Aug 2007 julien charton

now, even labVIEW freaks are impressed when I zoom in Matlab.

04 Nov 2007 Jakob Kleinbach

Such a great tool. Thank you!

05 Jan 2008 Dan Kanak

great help - thanks!!

23 Jul 2008 Efrain Zenteno

Works excellent

09 Feb 2009 Tue

problem with time series plotting: x-axis values are converted into numerical values.

22 May 2010 Robert

you are a hero. life is different now.

19 Sep 2010 Carla F.

Very nice work! Many thanks!!

Please login to add a comment or rating.
Updates
06 Apr 2006

Constrained zooming based on the movement of the mouse. Red indicator line shows the type of zoom. Added "Inspired By" files.

10 Apr 2006

Allow unconstrained zoom. <shift> key toggles constrained mode. Fix aspect ratio bug.

11 Apr 2006

Fixed more aspect ratio bugs. Now deals with all axes settings. It maintains the visual plot box size.

12 Apr 2006

Optimize code. Clean up documentation. Fix ticklabel jitter bug.

13 Apr 2006

Change the speed of animation during centering and view restoring. Add title bar indication for view centering and view restoring. Preserve aspect ratio when the DataAspectRatioMode is MANUAL. Display zoom factor on the graph.

24 Apr 2006

The zoom factor displayed on the graph is in relation to the original figure size, as opposed to the current figure size. Modify help text.

Tag Activity for this File
Tag Applied By Date/Time
data exploration Jiro Doke 22 Oct 2008 08:21:07
mouse Jiro Doke 22 Oct 2008 08:21:07
cursor Jiro Doke 22 Oct 2008 08:21:07
zoom Jiro Doke 22 Oct 2008 08:21:07
pan Jiro Doke 22 Oct 2008 08:21:07
view Jiro Doke 22 Oct 2008 08:21:07
interactive Jiro Doke 22 Oct 2008 08:21:07
exploration Jiro Doke 22 Oct 2008 08:21:07

Contact us at files@mathworks.com