add an line for the coasts of the continents used for the geodensityplot in the mapping toolbox

42 views (last 30 days)
I would like to add a coast line, an outline map of landmass on the plot for the geodensityplot in the mapping toolbox. I am using 2021b and the mapping toolbox.
basic code:
geodensityplot(dataLat,dataLong,[], 'FaceColor', 'interp');
gx = gca;
gx.Basemap = 'streets-light'; % This is the default, so not necessary
hold on
I tried using geoshow and hold on, but I cant get the entire coastline, just from 90W to 90E... For some reason the data isn't +/-180... I know that the lat and lon are reversed in geoshow below, but for some reason the coastline will only line up if I reverse them (see attached jped), just won't produce all the coast line... The attach first jpeg screenshot shows how it ends up with the lat and lon correct for geoshow and the second attached file if I reverse them...
coastline code:
load coastlines
geoshow(coastlon,coastlat,'Color','k') % Yes, this has the lon/lat reversed, but I can't get the coast line to trace the geodensity plot otherwise

Accepted Answer

Chunru
Chunru on 15 Oct 2021
Edited: Chunru on 15 Oct 2021
mapping toolbox has the convention of lat-lon coordinates rather than lon-lat. try the following in your code:
lon = linspace(-170,170,3000) + 10*rand(1,3000);
lat = 50 * cosd(3*lon) + 10*rand(size(lon));
weights = 101 + 100*(sind(2*lon));
% Create the geographic density plot, specifying the colors used with the plot.
geodensityplot(lat,lon,weights,'FaceColor','interp')
load coastlines
hold on
geoplot(coastlat, coastlon, 'b')
geobasemap('bluegreen')
  3 Comments
Mike Susedik
Mike Susedik on 15 Oct 2021
Edited: Mike Susedik on 15 Oct 2021
I swear to the gods of Matlab that I tried it both ways with lat/lon as the attached figures show... I ran your code and it of course worked fine. Then I ran my code and it gives me the 90 degree rotation.
I looked closer at my code and I'm using "geoshow" and you're using "geoplot". It seems geoshow is the wrong function for my application.
Why is geoshow wrong function? Key ingrediance is the word "line"?
geoshow : Display map latitude and longitude data
geoplot: Plot line in geographic coordinates
I don't know why lat/lon works one way for geoplot and the other way for geoshow? Maybe a bug?
Try this code and you'll see the problem I was getting, then swap lat/lon and see what you get:
lon = linspace(-170,170,3000) + 10*rand(1,3000);
lat = 50 * cosd(3*lon) + 10*rand(size(lon));
weights = 101 + 100*(sind(2*lon));
% Create the geographic density plot, specifying the colors used with the plot.
geodensityplot(lat,lon,weights,'FaceColor','interp')
load coastlines
hold on
geoshow(coastlat, coastlon,'Color', 'b')
geobasemap('bluegreen')
I'm using geoplot now and the computer is happy.
Thank you for the help Chunru!

Sign in to comment.

More Answers (0)

Categories

Find more on Geographic Plots in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!