Overplotting of scatter points on top of coastlines
7 views (last 30 days)
Show older comments
Hi all,
I am having a hard time figuring out how to plot a scatter plot on top of a worldmap without obscuring the coastlines. I have'nt used much of geoshow but I tried the following:
heat_data = load('struct.mat');
heat_data = heat_data.struct;
lat = heat_data.lat;
lon = heat_data.lon;
heat = heat_data.heat;
load coastlines
worldmap([-70,20],[-180,180])
geo = geoshow(coastlat,coastlon,"DisplayType","polygon","FaceColor",[1 1 1],'LineWidth',3);
sc = scatterm(lat,lon,75,heat,'filled','s');
sc.Children.MarkerFaceAlpha = 0.5;
sc.Children.MarkerEdgeAlpha = 0.5;
setm(gca,'FontSize',15) % setting fontsize of lat, lon ticklabels
setm(gca,'GLineWidth',2.5)
setm(gca,'GColor','k')
set(geo,'LineWidth',3)
%%%¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ Setting the colormap
colormap('jet')
caxis([0 20000])
col = colorbar();
As clearly seen, while doing the scatter plot on top of the worldmap, most of the coastlines of South America and the southern part of Africa are not visible. I tried to reduce the transparency of the scatter markers but still they dont seem to work. However, I am able to adjust the thickness of the grid lines which seems unaffected by the color markers, even though adjusting the thickness of the coastlines are not working!
Does anyone have a lead to circumvent this?
Thanks a lot!
0 Comments
Accepted Answer
Cris LaPierre
on 12 Dec 2023
Why not reverse the plot order? Plot your scatter first, and then your coastlines on top of them?
I did have to modify some of the settings in geoshow so that the land area does not block the scatter points.
heat_data = load('struct.mat');
heat_data = heat_data.struct;
lat = heat_data.lat;
lon = heat_data.lon;
heat = heat_data.heat;
load coastlines
worldmap([-70,20],[-180,180])
sc = scatterm(lat,lon,75,heat,'filled','s');
geo = geoshow(coastlat,coastlon,'LineWidth',3,'Color','k');
sc.Children.MarkerFaceAlpha = 0.5;
sc.Children.MarkerEdgeAlpha = 0.5;
setm(gca,'FontSize',15) % setting fontsize of lat, lon ticklabels
setm(gca,'GLineWidth',2.5)
setm(gca,'GColor','k')
set(geo,'LineWidth',3)
%%%¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ Setting the colormap
colormap('jet')
caxis([0 20000])
col = colorbar();
3 Comments
Cris LaPierre
on 13 Dec 2023
Here is your original code
geo = geoshow(coastlat,coastlon,"DisplayType","polygon","FaceColor",[1 1 1],'LineWidth',3);
Here is the updated code in my answer
geo = geoshow(coastlat,coastlon,'LineWidth',3,'Color','k');
You can find the axes-based map properties page here: https://www.mathworks.com/help/map/ref/axesm-properties.html
More Answers (1)
Walter Roberson
on 12 Dec 2023
Edited: Walter Roberson
on 12 Dec 2023
As well as long placing the scatterm() on the bottom, you need to watch out for the face color, because the face normally blocks view of what is behind it.
heat_data = load('struct.mat');
heat_data = heat_data.struct;
lat = heat_data.lat;
lon = heat_data.lon;
heat = heat_data.heat;
load coastlines
worldmap([-70,20],[-180,180])
sc = scatterm(lat,lon,75,heat,'filled','s');
geo = geoshow(coastlat,coastlon,"DisplayType","polygon", "FaceColor", 'none', "EdgeColor", 'k', 'LineWidth',3);
sc.Children.MarkerFaceAlpha = 0.5;
sc.Children.MarkerEdgeAlpha = 0.5;
setm(gca,'FontSize',15) % setting fontsize of lat, lon ticklabels
setm(gca,'GLineWidth',2.5)
setm(gca,'GColor','k')
set(geo,'LineWidth',3)
%%%¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ Setting the colormap
colormap('jet')
caxis([0 20000])
col = colorbar();
See Also
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!