Error using geobasemap in subplot

18 views (last 30 days)
Sagar Parajuli
Sagar Parajuli on 26 Jul 2023
Commented: Cris LaPierre on 26 Jul 2023
I am trying to plot some geolocated data with geoscatter as below:
geobasemap grayterrain
geolimits([35.79 40],[-124.8552 -119.3342]);
geoscatter(lat_stn, lon_stn, data_sum, data_sum, 'filled');
clim([0, 80]);
colorbar;
The above code works perfectly well and plots the data in a given basemap.
However, when I try to plot the exact above thing in a subplot I get some errors:
subplot (1, 2, 2)
geobasemap grayterrain
geolimits([35.79 40],[-124.8552 -119.3342]);
geoscatter(lat_stn, lon_stn, data_sum, data_sum, 'filled');
clim([0, 80]);
colorbar;
The error I get is:
Error using geobasemap>parseInputs
Unable to use geobasemap. Current axes or chart is not geographic.
Error in geobasemap (line 30)
[gx, basemap, usingBasemapSyntax] = parseInputs(varargin);
Error in spatial_madis_model_comparison_geobubble (line 94)
geobasemap grayterrain
Could you please advise how to fix this issue?

Answers (1)

Cris LaPierre
Cris LaPierre on 26 Jul 2023
Edited: Cris LaPierre on 26 Jul 2023
subplot creates a cartesian axes in the current position. Since you call geobasemap and geolimits before geoscatter, they attemp to operate on the cartesian axes, which is not allowed.
Try changing the order of your code so that you call geoscatter first, which does create a geographic axes, and then geolimits and geobasemap
subplot(1,2,2)
lat = [42.3501 42.3598 42.3626 42.3668 42.3557];
lon = [-71.0870 -71.0662 -71.0789 -71.0801 -71.0662];
geoscatter(lat,lon,"filled")
geolimits([42.3456 42.3694],[-71.0930 -71.0536])
geobasemap grayterrain
clim([0, 80]);
colorbar;
  4 Comments
Sagar Parajuli
Sagar Parajuli on 26 Jul 2023
So you mean there is no solution to this? I can query the geolimits used but the limits that I specified are not working, that is my problem. I read that there is a 'manual' mode for geolimits but that stil doesn't allow to specify the limits.
Cris LaPierre
Cris LaPierre on 26 Jul 2023
This is the documented behavior of geolimits.
The geolimits function typically uses wider limits than the limits you specify to maintain the aspect ratio of the map.

Sign in to comment.

Categories

Find more on Geographic Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!