Setting manually limits in geoplot

29 次查看(过去 30 天)
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
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