Reset to Original View with zoom
52 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Jerry Gregoire
am 3 Jun. 2015
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
Antworten (1)
Martin
am 13 Feb. 2018
Bearbeitet: Martin
am 16 Aug. 2021
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 Kommentare
Thomas Carpenter
am 15 Aug. 2021
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 ) .
Siehe auch
Kategorien
Mehr zu Lighting, Transparency, and Shading finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!