MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi
Opportunities for recent engineering grads.
New to MATLAB?
In a figure window toolbar, there are spyglass icons that let you zoom in and out on parts of an image or plot. I'd like to know how to do this programmatically.
Direct link to this comment:
I have a figure with the plots and axes out of screen and no scroll bar. Please I need help shrinking the plot size.
No products are associated with this question.
There is a function "zoom" with the following options :
h = zoom(figure_handle)
Thanks. What I still can't see, though, is how you determine the "center" of the zoom. When zooming interactively, the position of the mouse pointer determines the position of the zoomed view, but I can't see how to set that with the ZOOM command.
hi Matt J,
So far you can control the direction H/V in the figure :
You have to control the figure properties then a zoom will be applied based on those parameters ( get(figure(1)), the property that concerns us is the "CurrentPoint" property, here is an example :
new_position=[200 300]; % an example
The zoom is focused in that point , of course this approach may seem not efficient because you need preliminary knowledge about the data cursor .
Yeah, it's always a pain because zoom(factor) is relative. So if you're zooming something like an image you always have to reset the zoom and then call it again with the factor, or else you have to keep track of the absolute zoom level yourself. I have code for a zoom scrollbar if you're interested.
Well, I was mainly after a programmatic way to duplicate the spyglass figure window icon functionality... But how is the zoom scrollbar different from the spyglass?
It's not. The scroll bar just give you an absolute zoom level, which is the scroll bar value. So then you just do zoom('out') everytime to reset it back to the starting zoom, and then zoom(scrollbarValue) in the callback of the scrollbar.
% --- Executes on slider movement.
function sldZoom_Callback(hObject, eventdata, handles)
% hObject handle to sldZoom (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% scrollbarValue = get(hObject,'Value');
% caption = sprintf('H value = %.2f', scrollbarValue);
% set(handles.txtZoom, 'string', caption);
zoomFactor = get(hObject,'Value');
txtInfo = sprintf('Zoom Factor = %.2f (%d %%)\n\nOnce zoomed, you can pan by clicking and dragging in the image.', zoomFactor, round(zoomFactor * 100));
set(handles.txtInfo, 'String', txtInfo);
txtInfo = sprintf('Zoom Factor = %.2f\n\nOnce zoomed, you can pan by clicking and dragging in the image.', zoomFactor);
set(handles.sldZoom, 'TooltipString', txtInfo);
txtZoom = sprintf('Zoom Factor = %.2f (%d %%)', zoomFactor, round(zoomFactor * 100));
set(handles.txtZoom, 'String', txtZoom);
% if zoomFactor ~= 1
% Set up to allow panning of the image by clicking and dragging.
% Cursor will show up as a little hand when it is over the image.
set(handles.axesImage, 'ButtonDownFcn', 'disp(''This executes'')');
set(handles.axesImage, 'Tag', 'DoNotIgnore');
h = pan;
set(h, 'ButtonDownFilter', @myPanCallbackFunction);
set(h, 'Enable', 'on');
message = sprintf('Error in sldZoom_Callback():\n%s', ME.message);
return; % from sldZoom_Callback
Direct link to this answer: