Thread Subject: Zoom mode in 3D graphs

Subject: Zoom mode in 3D graphs

From: Andy

Date: 25 Aug, 2009 14:56:02

Message: 1 of 3

MATLAB documentation gives the following as an example of programmatically setting zoom properties:

ax1 = subplot(2,2,1);
plot(1:10);
h = zoom;
ax2 = subplot(2,2,2);
plot(rand(3));
setAllowAxesZoom(h,ax2,false);
ax3 = subplot(2,2,3);
plot(peaks);
setAxesZoomMotion(h,ax3,'horizontal');
ax4 = subplot(2,2,4);
contour(peaks);
setAxesZoomMotion(h,ax4,'vertical');

This example works just fine. But if you make this little change:

ax1 = subplot(2,2,1);
plot(1:10);
h = zoom;
ax2 = subplot(2,2,2);
plot(rand(3));
setAllowAxesZoom(h,ax2,false);
ax3 = subplot(2,2,3);
surf(peaks); % <- surf instead of plot
setAxesZoomMotion(h,ax3,'horizontal');
ax4 = subplot(2,2,4);
contour(peaks);
setAxesZoomMotion(h,ax4,'vertical');

then zooming in the 3D graph does not work as the documentation suggests. The documentation says: "zoom changes the axes limits by a factor of 2 (in or out) each time you press the mouse button while the cursor is within an axes." But when zooming in a 3D graph, the graph doubles in size, taking over the figure. Obviously, having a subplot become the background image for my GUI was not what I wanted. Is there any way to change this behavior?

Subject: Zoom mode in 3D graphs

From: Andy

Date: 25 Aug, 2009 16:09:18

Message: 2 of 3

Here's a simple GUI that demonstrates some more strange behavior:

f=figure('Menu','none');
um=uimenu('Parent',f,'Label','graph');
umz=uimenu('Parent',um,'Label','zoom','accelerator','z','Callback','zoom');
umr=uimenu('Parent',um,'Label','rotate','accelerator','r','Callback','rotate3d');
pan=uipanel('Parent',f,'Position',[.2 .2 .6 .6]);
ax=axes('Parent',pan);
surf(peaks);


1. Same zoom problem as before. If you turn on the zoom and start zooming in, the graph grows beyond the boundaries of the parent panel, rather than changing the limits of the axis as the documentation claims.
2. Toggling the zoom via the accelerator does not work the same as toggling the zoom via the menu. For example, start up the GUI, enable rotate (using the menu or accelerator), and rotate the graph. Then, if you go to the menu and enable zoom, the graph stays rotated. If you instead use the accelerator to enable zoom, the graph returns to its original orientation.
3. Run the GUI, enable zooming using the accelerator and zoom in a few times. Then double click to return to the original view. Then use the accelerator to toggle zoom mode on and off (without actually zooming in or out while in zoom mode). Rather than maintain the graph's current zoom level, toggling the zoom seems to go through several zoom levels. Again, this happens only when using the accelerator, not when using selecting the zoom option in the menu.

Subject: Zoom mode in 3D graphs

From: Andy

Date: 25 Aug, 2009 20:20:23

Message: 3 of 3

I think I've figured out the problems.

1. Even though 'Z' is not a reserved uimenu accelerator, it's used in the internal function localKeyPressFcn in zoom.m as the undo shortcut (big surprise). I switched the accelerator to something else, so now I can toggle into and out of zoom mode without resizing the graph incorrectly.

2. The actual zooming in a 2D graph is done in the localDoZoom2D internal function in zoom.m, while the zooming for a 3D graph occurs in localOneShot3DZoom. The 2D zooming explicitly resets the x and y limits. The 3D graphing just calls camzoom to zoom in and out, and this makes no attempt to restrict the size of the surface as you zoom in.

I don't actually have a solution to the second problem. Perhaps I just have to live with it. (I would prefer not to rewrite the zoom.m function for my company's version of MATLAB.) But I think while I was looking around I discovered a way to add things to the context menu's in zoom(/pan/datacursor/etc.) modes (or probably any mode that creates a default context menu). In the localUICreateDefaultContextMenu at line 2075, the context menu is created with the Tag set to "ZoomContextMenu". I'm not at MATLAB right now, but I would guess that similar context menus are created in the other modes, and that you could use findobj to get the handle of the menu so that you could add things to it. Maybe I'll try this out tomorrow.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
zoom Andy 25 Aug, 2009 10:59:04
3d graph Andy 25 Aug, 2009 10:59:04
rssFeed for this Thread

Contact us at files@mathworks.com