필터 지우기
필터 지우기

how to zoom-out on a figure window in a script

조회 수: 57 (최근 30일)
Marc Compere
Marc Compere 2020년 8월 9일
편집: Marc Compere 2020년 8월 11일
Sometimes matlab figures have axes too tight to see the data, or to see text labels added to data points. Is there a simple command to zoom out by 10% without mousing over the figure window. this needs to happen in a script at the command line.
This is my solution but is a few lines too long. Looking for a clean, simple 1-liner:
figure, plot(rand(10,1),'bo-')
% zoom out by 10%
ax=axis; % get [xmin xmax ymin ymax]
dx=ax(2)-ax(1); % dy=xmax-xmin
dy=ax(4)-ax(3); % dy=ymax-ymin
axis([ ax(1)-0.1*dx , ax(2)+0.1*dx , ax(3)-0.1*dy , ax(4)+0.1*dy ]);

답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2020년 8월 9일
Hi,
Here are two simple ways of solving your task:
1) using zoom() function, e.g.:
figure, plot(rand(10,1),'bo-')
zoom(0.75) % any magnification or lessenning factor used for xmin and ymin and ymax NOT for xmax
Or using an alternative way with the next two commands:
AX=axis;
set(gca,'XLim',[AX(1)*0.1 AX(2)*1.1],'YLim',[AX(3)*0.1 AX(4)*1.1]) % This gives 10% of zoom out
  댓글 수: 1
Marc Compere
Marc Compere 2020년 8월 10일
편집: Marc Compere 2020년 8월 11일
Hello,
The first answer does not zoom-out when already at the Matlab defaults. This is not a viable solution.
The second answer is almost equivalent to the example provided, however it performs a multiplication on all axes extents. This is not sufficient because when any of them are zero (which occurs easily) there is no change. All four axes extents must be adjusted with addition or subtraction.
It seems there's no simpler way than the original post.
This could be a feature request for Mathworks.
MDC

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

카테고리

Help CenterFile Exchange에서 Visual Exploration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by