Mapping issue with pcolor()
Ältere Kommentare anzeigen
When I use pcolor() to show the raster data, there seems something wrong with the data, as shown in the figure below. But using pcolorm(), the data can be correctly mapped. Does anyone know why? The following code is provided by Austin M. Weberhttps://www.mathworks.com/matlabcentral/answers/2092826-changing-the-longitude-of-netcdf-from-0-360-to-180-180?s_tid=mlc_ans_email_view#comment_3101196.
% Repeating the first part
load cpc.mat
lat = double(lat);
lon = double(lon);
mask = lon > 180;
lon(mask) = lon(mask) - 360;
lat = flip(lat);
tmax = flipud(tmax');
% Repeating making a new netcdf file
file_name = 'new.nc';
ncid = netcdf.create(file_name, 'NETCDF4');
lat_len = length(lat);
lon_len = length(lon);
lat_dim = netcdf.defDim(ncid, 'lat', lat_len);
lon_dim = netcdf.defDim(ncid, 'lon', lon_len);
lat_var = netcdf.defVar(ncid, 'lat', 'double', lat_dim);
lon_var = netcdf.defVar(ncid, 'lon', 'double', lon_dim);
tmax_var = netcdf.defVar(ncid, 'tmax', 'double', [lat_dim, lon_dim]);
netcdf.endDef(ncid);
netcdf.putVar(ncid, lat_var, lat);
netcdf.putVar(ncid, lon_var, lon);
netcdf.putVar(ncid, tmax_var, tmax);
netcdf.close(ncid);
% Visualize
mync = ncread('new.nc','tmax');
lat = ncread('new.nc','lat');
lon = ncread('new.nc','lon');
figure(1)
subplot(2,1,1)
pcolor(lon, lat, mync)
title('Cartesian Axes with pcolor()')
colorbar
shading interp
axis equal tight
grid on
subplot(2,1,2)
axesm('eqdcylin')
pcolorm(lat, lon, mync)
title('Map Axes with pcolorm()')
colorbar
shading interp
tightmap
gridm
mlabel('south') % Longitude tick labels
plabel('on') % Latitude tick labels

Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Interact with Maps finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
