I want to show precipitation data on the world map
This code does not appear to indicate the exact amount of precipitation in latitude and longitude
Please help me
clc; clear all;
fnm = 'precip.mon.ltm.1981-2010.nc'
lon=double(ncread(fnm,'lon'));
lat=double(ncread(fnm,'lat'));
time=ncread(fnm,'time');
dateT=datetime(1800,01,01,00,00,00)+days(time);
precip=ncread(fnm,'precip');
load coastlines; % Load coastline data
[X, Y] = meshgrid(lon, lat);
for month = 1:12
f = figure;
% Create world map projection
worldmap('world');
setm(gca, 'Origin', [0 180 0]); % Set map origin to be the equator
% Plot precipitation data on the world map
surfm(X', Y', precip(:, :, month)); % Use surfm to plot data on the map
cmap = brewermap(16, 'BrBG'); % Generate the colormap
colormap(cmap); % Apply the colormap to the current figure
cb = colorbar; % Create a colorbar
cb.Label.String = 'mm/day';
clim([0 16]); % Set color axis limits
cb.Ticks = 0:1:16;
% Overlay coastlines
plotm(coastlat, coastlon, 'k', 'LineWidth', 1); % Plot coastlines on top of precipitation data
% Add title with month name
title(sprintf('Average Monthly Precipitation (1981-2010) - %s', datestr(dateT(month), 'mmmm')));
% Save each figure as an image file
filename = sprintf('E:\\Koppen-Geiger climate classes\\Average_Monthly_Precipitation%d.png', month);
saveas(f, filename);
close(f);
end

댓글 수: 5

Rahul
Rahul 2024년 11월 18일
It would be helpful if you could provide 'precip.mon.ltm.1981-2010.nc' file, to better understand the issue.
Angelo Yeo
Angelo Yeo 2024년 11월 18일
@Rahul, you can download the data from the webpage below ;)
은진
은진 2024년 11월 19일
Thank you so much~~!!!
Kanishk
Kanishk 2024년 11월 25일
Hi @은진, With code and data provided I was able to produce this image.
Could you clarify what is the issue or any missing feature you expect from the plot?
은진
은진 2024년 11월 28일
The precipitation data seems to have mismatched latitude and longitude coordinates.

댓글을 달려면 로그인하십시오.

 채택된 답변

O.K.D. Adeesha
O.K.D. Adeesha 2025년 1월 13일
편집: Walter Roberson 2025년 1월 13일

0 개 추천

clc; clear all;
% Load data
fnm = 'precip.mon.ltm.1981-2010.nc';
lon = double(ncread(fnm, 'lon')); % Longitude
lat = double(ncread(fnm, 'lat')); % Latitude
time = ncread(fnm, 'time'); % Time
dateT = datetime(1800, 01, 01, 00, 00, 00) + days(time);
precip = ncread(fnm, 'precip'); % Precipitation data
% Coastline data
load coastlines;
% Create grid for data
[X, Y] = meshgrid(lon, lat);
% Adjust longitude range if needed
if max(lon) > 180
lon = mod(lon + 180, 360) - 180; % Convert to [-180, 180]
[X, Y] = meshgrid(lon, lat); % Recreate grid
end
% Loop through months
for month = 1:12
f = figure;
% World map projection
worldmap([min(lat) max(lat)], [min(lon) max(lon)]);
setm(gca, 'Origin', [0 180 0]); % Set map origin to the equator
% Ensure data is correctly oriented
precip_data = squeeze(precip(:, :, month)); % Extract monthly data
precip_data = precip_data'; % Ensure alignment with X, Y
% Plot precipitation data
surfm(Y, X, precip_data);
% Colormap and colorbar
cmap = brewermap(16, 'BrBG'); % Use brewermap if available
colormap(cmap);
cb = colorbar;
cb.Label.String = 'mm/day';
clim([0 max(precip_data(:))]); % Adjust color limits dynamically
cb.Ticks = 0:2:max(precip_data(:)); % Adjust ticks dynamically
% Overlay coastlines
plotm(coastlat, coastlon, 'k', 'LineWidth', 1);
% Add title with month name
title(sprintf('Average Monthly Precipitation (1981-2010) - %s', datestr(dateT(month), 'mmmm')));
% Save figure
filename = sprintf('E:\\Koppen-Geiger climate classes\\Average_Monthly_Precipitation_%d.png', month);
saveas(f, filename);
close(f);
end
Explanation of Changes
  1. Longitude Adjustment:If your data uses 0–360 longitude, convert it to -180–180 for proper alignment on the map.
  2. Dynamic Color Limits:Adjust clim dynamically using max(precip_data(:)) instead of hardcoding 16.
  3. Data Orientation:Ensure precip_data aligns with X and Y by transposing it.
  4. Visualization Enhancements:Added dynamic ticks for the colorbar and ensured proper handling of color limits.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Weather and Atmospheric Science에 대해 자세히 알아보기

제품

릴리스

R2024a

질문:

2024년 11월 18일

편집:

2025년 1월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by