필터 지우기
필터 지우기

Setting manually limits in geoplot

조회 수: 29 (최근 30일)
Vinícius Ludwig Barbosa
Vinícius Ludwig Barbosa 2021년 8월 19일
댓글: Vinícius Ludwig Barbosa 2021년 8월 20일
Is there a way to set precisely the limits of a geoplot, e.g.
gx = geoaxes;
geolimits([-45 45], [-180 180]);
and "lock" this ratio as much as possible no matter how I resize the figure window?

채택된 답변

Dave B
Dave B 2021년 8월 20일
This is a somewhat crazy approach, and won't work for very really extreme figure sizes. geoaxes is trying to fill the window, and maintain a fixed lat/long aspect ratio, but doesn't appear to have any sort of PlotBoxAspectRatio. I fudged the numbers a tad below because it was effective on my display, you might have to play a bit with the values.
gx = geoaxes;
geolimits([-45 45], [-180 180]);
%ar=90/360;
ar=90/320;
gx.Units='pixels';
f=gcf;
f.SizeChangedFcn=@(~,~)myresizefcn(gx, f, ar);
myresizefcn(gx,f,ar)
function myresizefcn(gx,f,ar)
if (f.Position(4)/f.Position(3))<ar
% wide: height is constraint
gx.Position(4)=f.Position(4) * .8;
gx.Position(3)=gx.Position(4) / ar;
% centering:
gx.Position(1)=f.Position(3)/2 - gx.Position(3)/2;
gx.Position(2)=f.Position(4)/2 - gx.Position(4)/2;
% re-nudge limits
geolimits([-45 45], [-180 180]);
else
% tall: width is constraint
gx.Position(3)=f.Position(3) * .8;
gx.Position(4)=gx.Position(3) * ar;
% centering:
gx.Position(1)=f.Position(3)/2 - gx.Position(3)/2;
gx.Position(2)=f.Position(4)/2 - gx.Position(4)/2;
% re-nudge limits
geolimits(gx,[-45 45], [-180 180]);
end
end
  댓글 수: 1
Vinícius Ludwig Barbosa
Vinícius Ludwig Barbosa 2021년 8월 20일
It works perfectly! Thanks @Dave B
Minor fix at myresizefcn, last line in else statement:
geolimits([-45 45], [-180 180]); %previously geolimits(gx,[-45 45], [-180 180]);

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Geographic Plots에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by