Reset to Original View with zoom
52 次查看(过去 30 天)
显示 更早的评论
I have a problem with the "Reset to Original View" command when I use the zoom:
If I enter:
figure; plot(rand(1,500)); h=gca; set(h,'xlim',[100 300]);
the curve if plotted between x=100 and x=300 and each time I use the "Reset to Original View" command after a zoom, the curve is still plotted between 100,300 and not 0,500 as it was originally.
Now, if I enter:
figure; plot(rand(1,500));
I zoom on the figure and I use the "Reset to Original View" command and then I enter:
h=gca; set(h,'xlim',[100 300]);
the curve if plotted between x=100 and x=300 but each time I use the "Reset to Original View" command after a zoom, the curve is plotted between 0,500.
How does this work?
How can I reset the curve between 0,500 without doing a zoom between the command "plot" and the command "set" ?
1 个评论
Jerry Gregoire
2015-6-3
When you set 'xlim', the xlimmode is set to manual. This disables the ability to go 'reset' to the true extents of the plot. Do this set(gca,'xlimMode', 'auto') and similarly for y and/or z
回答(1 个)
Martin
2018-2-13
编辑:Martin
2021-8-16
Hello Christophe,
A little bit late..... but here is a solution. (Maybe I can help someone else with this problem.)
Add the next command before setting the limits:
resetplotview(hA,'InitializeCurrentView');
So the total code will look like:
figure;
plot(rand(1,500));
hA = gca;
% resetplotview(hA,'InitializeCurrentView'); %tested in 2013b
zoom(hA, 'reset'); %tested in 2019a
set(hA,'xlim',[100 300]);
Now you are able to use "Reset to Original View" to zoom out to the full axes (1 till 500).
NOTE: "resetplotview" is not a official documented function. Matlab can remove or change the function in the future.
3 个评论
Thomas Carpenter
2021-8-15
For future readers, it seems the proper documented(-ish) way of doing this is to use the zoom() function.
Instead of the call to resetplotview(hA,...), do zoom(hA,'reset'). This will accomplish the same thing, setting the extents of the zoom when clicking "Reset to Original View", but using a documented interface.
The only slightly undocumented thing about using zoom in this way is that all the documentation says that the first argument should be a figure handle. In fact it works perfectly fine if the first argument is an axes handle ( zoom uses ancestor to find the appropriate figure and then uses the provided axis handle ) .
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!