How to zoom in/out on an axis programmatically

93 次查看(过去 30 天)
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.
  1 个评论
John
John 2015-4-17
I have a figure with the plots and axes out of screen and no scroll bar. Please I need help shrinking the plot size.

请先登录,再进行评论。

采纳的回答

Youssef  Khmou
Youssef Khmou 2013-5-22
hi,
There is a function "zoom" with the following options :
zoom on
zoom off
zoom out
zoom reset
zoom xon
zoom yon
zoom(factor)
zoom(fig, option)
h = zoom(figure_handle)
  9 个评论
Kyle Chappell
Kyle Chappell 2017-1-11
hObject is the object handle. It's passed as a default argument when accessing the callback function of uicontrol objects. For instance, if you have a uibutton, e.g. 'Go', 'Save', 'Next', the handle to the button object will be passed. This gives you access to the object properties like Position, String, buttonDownFcn, etc. and allows you to access their values or edit them.
This may not always be the case, I'm not an expert, but I've run into this a lot when building GUIs, whether using GUIDE or not.
To ensure the accuracy of what I've said on your own, I suggest you build something with GUIDE, set a breakpoint after a function calling hObject and using get(hObject) to view the accessible properties. Using get(handles.pushbutton1), for example, should be the same as get(hObject) when used in pushbutton1's callback function. I can't be sure, I don't have MATLAB open in front of me right now.
Feel free to correct me if I'm wrong. I'm always open to learning something new.

请先登录,再进行评论。

更多回答(2 个)

Mike Smith
Mike Smith 2016-8-17
If you know the zoom level that you want, you can do it by setting the Xlim and Ylim on the Children of the figure handle. So if you wanted to zoom the x axis between 400 and 500 you could do: h=gcf; set(h.Children,'Xlim',[400 500]);

shaik
shaik 2022-9-12
ax = gca;
ax.XLim = [lowerxvalue upperxvalue];
ax.YLim = [loweryvalue upperyvalue];

类别

Help CenterFile Exchange 中查找有关 Data Exploration 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by