Clear Filters
Clear Filters

Setting manually limits in geoplot

29 views (last 30 days)
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?

Accepted Answer

Dave B
Dave B on 20 Aug 2021
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 Comment
Vinícius Ludwig Barbosa
Vinícius Ludwig Barbosa on 20 Aug 2021
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]);

Sign in to comment.

More Answers (0)

Categories

Find more on Geographic Plots in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!