Borrar filtros
Borrar filtros

Reset to Original View with zoom

73 visualizaciones (últimos 30 días)
Christophe
Christophe el 7 de Dic. de 2011
Comentada: Martin el 16 de Ag. de 2021
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 comentario
Jerry Gregoire
Jerry Gregoire el 3 de Jun. de 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

Iniciar sesión para comentar.

Respuestas (1)

Martin
Martin el 13 de Feb. de 2018
Editada: Martin el 16 de Ag. de 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.
EDIT: The solution of @Thomas Carpenter is working voor more recent versions.
  3 comentarios
Thomas Carpenter
Thomas Carpenter el 15 de Ag. de 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 ) .
Martin
Martin el 16 de Ag. de 2021
thanks @Thomas Carpenter I update my solution

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by