How to combine pcolor map to geodensityplot map?

9 vues (au cours des 30 derniers jours)
Chun Long Wong
Chun Long Wong le 7 Nov 2021
I wanted to combine the lightning data and temperature data into one map, I was trying to combine the pcolor map and geodensityplot map. However, it showed that :
Error using geodensity plot, adding Geographics to Axes is not supported.
Then I looked through other solutions in the Community and it seemed not applicable for my case. May I know what can I do? Thank you very much.
My code was:
ncdisp("temp.nc")
lat=ncread("temp.nc","lat")
lon=ncread("temp.nc","lon")
temp=ncread("temp.nc","dpt")
temp1=temp(:,:,145)
map=pcolor(lon,lat,temp1)
map.EdgeAlpha=0
colorbar
caxis([223 323])
load Lightning_WWLLN_201701
mix=[lightning.lat lightning.lon]
mix(lightning.lat<18 | lightning.lat>45 | lightning.lon<90 | lightning.lon>130,:)=[]
hold on
geodensityplot(mix(:,1),mix(:,2),'FaceColor','interp')
colorbar

Réponses (1)

AKennedy
AKennedy le 4 Avr 2024
Hey,
To combine lightning data and temperature data into one map and avoid the error you're encountering, you should use a geographic plotting function for both datasets instead of mixing Cartesian plotting "pcolor" with geographic plotting "geodensityplot". Here's a simplified approach:
  1. Plot Temperature Data on a Geographic Map: Use "geoshow" or another geographic plotting function to display your temperature data on a map. This ensures the plot is in a geographic context.
  2. Overlay Lightning Data: On the same geographic plot, overlay your lightning data using "geodensityplot".
Here's a short example:
% Load temperature data
lat = ncread("temp.nc", "lat");
lon = ncread("temp.nc", "lon");
temp = ncread("temp.nc", "dpt");
temp1 = temp(:,:,145);
% Create a geographic map for temperature data
figure;
worldmap('World');
geoshow(lat, lon, temp1, 'DisplayType', 'texturemap');
caxis([223 323]); % Adjust temperature range
colorbar;
% Load and overlay lightning data
load Lightning_WWLLN_201701; % Assuming this loads lightning data
mix = [lightning.lat, lightning.lon];
geodensityplot(mix(:,1), mix(:,2), 'FaceColor', 'interp');
colorbar;
This approach keeps everything within a geographic plotting context, avoiding the error you encountered.

Catégories

En savoir plus sur Geographic Plots dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by