Borrar filtros
Borrar filtros

Setting manually limits in geoplot

29 visualizaciones (últimos 30 días)
Vinícius Ludwig Barbosa
Vinícius Ludwig Barbosa el 19 de Ag. de 2021
Comentada: Vinícius Ludwig Barbosa el 20 de Ag. de 2021
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?

Respuesta aceptada

Dave B
Dave B el 20 de Ag. de 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 comentario
Vinícius Ludwig Barbosa
Vinícius Ludwig Barbosa el 20 de Ag. de 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]);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Geographic Plots en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by