File Exchange

image thumbnail

Mouse-friendly FIGURE

version (3.98 KB) by Rody Oldenhuis
Same as FIGURE, but zooming/panning is done more conveniently with scroll wheel/clicks.


Updated 10 Jun 2018

GitHub view license on GitHub

MOUSE_FIGURE(handle) creates a figure (or modifies an existing one with handle [handle]) that allows zooming with the scroll wheel and panning with mouse clicks, *without* first selecting the ZOOM or PAN tools from the toolbar. Moreover, zooming occurs to and from the point the mouse currently hovers over, instead of to and from the less intuitive "CameraPosition" as is the case with the default ZOOM. Naturally, the classical ZOOM and PAN toolbar icons are left unaltered.
Mouse button functionality:
Scroll: zoom in/out
Left click: pan
Double click: reset view to default view
Right click: set new default view
LIMITATIONS: This function (re-)efines several functions in the figure (WindowScrollWheelFcn, WindowButtonDownFcn, WindowButtonUpFcn and WindowButtonMotionFcn), so if you have any of these functions already defined they will get overwritten. Also, MOUSE_FIGURE() only works properly for 2-D plots. As such, it should only be used for simple, first-order plots intended for "quick-n-dirty" data exploration. Only tested on MATLAB 2009a, on WinXP platform.

x = linspace(-1, 1, 10000);
y = sin(1./x);
plot(x, y)

If you find this work useful, please consider a donation:

Comments and Ratings (13)

Quite useful. Thanks.


very nice. only behavior missing for me is the auto zoom, when you double click in the figure. It sets the axis to [01 01] instead of making the whole plot visible. All the other handling is very nice

just what I was looking for!! thanks :)

Excellent! Just what I needed. Simple and effective. Modified it slightly for x-only zoom.

Amin Memari





Very intuitive controls to explore 2D data :)


- updated PayPal link

[linked to Github]

Updated contact info

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: Ginput with snap to grid, akZoom