필터 지우기
필터 지우기

Reset to Original View with zoom

조회 수: 73 (최근 30일)
Christophe
Christophe 2011년 12월 7일
댓글: Martin 2021년 8월 16일
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
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
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.
EDIT: The solution of @Thomas Carpenter is working voor more recent versions.
  댓글 수: 3
Thomas Carpenter
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 ) .
Martin
Martin 2021년 8월 16일
thanks @Thomas Carpenter I update my solution

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by