フィルターのクリア

How can I plot contour lines on the generated map?

2 ビュー (過去 30 日間)
Behrooz Daneshian
Behrooz Daneshian 2023 年 2 月 20 日
コメント済み: Walter Roberson 2023 年 2 月 20 日
Hi all,
Using the first section of code below, I could generate map of Alaska state. I need to draw contour lines (second section of the code) on the generated map. Can anyone help me with this regard? Please use .shp file in the zipped folder,
%%%%% generating Alaska map
S=shaperead('Location of the .shp file\tl_2018_02_anrc.shp','UseGeoCoords',true);
geoshow(S,"DisplayType","multipoint")
xlim([-179.148909,-130]);
ylim([51.214183,71.365162]);
%%%%%%%% generating contour lines based on the latitude and longitude of
%%%%%%%% weather stations within the Alaska sate
load('POFDE.mat');
data = cell2mat(POFDE);
[lat,lon] = meshgrid(unique(data(:,1)),unique(data(:,2)));
for i = 1:(size(data, 2)-2)
figure
I = scatteredInterpolant(data(:,[1 2]), data(:,i+2));
contourm(lat,lon,min(1,max(0,I(lat,lon))),'ShowText','on')
colorbar
title(['The probability of frost depth exceedance of \Omega_{\delta} = ' num2str(i) ' feet'])
exportgraphics(gca, sprintf('FrostPlot_%d_feet.png', i))
end
  1 件のコメント
Walter Roberson
Walter Roberson 2023 年 2 月 20 日
You do not need meshgrid() for contour() . contour() will accept vectors of coordinates.
meshgrid() or ndgrid() are useful in cases where the Z coordinate is being calculated, or the Z value is being interpolated, but these days many of the graphing functions accept marginal vectors.

サインインしてコメントする。

採用された回答

Voss
Voss 2023 年 2 月 20 日
In your code, you make the map then create a new figure for each contour. Those new figures aren't going to have the map; the map was in the first figure. To have a map in each figure, call geoshow after figure.
unzip('tl_2018_02_anrc.zip')
%%%%% generating Alaska map
% S=shaperead('Location of the .shp file\tl_2018_02_anrc.shp','UseGeoCoords',true);
S=shaperead('tl_2018_02_anrc.shp','UseGeoCoords',true);
%%%%%%%% generating contour lines based on the latitude and longitude of
%%%%%%%% weather stations within the Alaska sate
load('POFDE.mat');
data = cell2mat(POFDE);
[lat,lon] = meshgrid(unique(data(:,1)),unique(data(:,2)));
for i = 1:(size(data, 2)-2)
figure
geoshow(S,"DisplayType","multipoint")
xlim([-179.148909,-130]);
ylim([51.214183,71.365162]);
I = scatteredInterpolant(data(:,[1 2]), data(:,i+2));
contourm(lat,lon,min(1,max(0,I(lat,lon))),'ShowText','on')
colorbar
title(['The probability of frost depth exceedance of \Omega_{\delta} = ' num2str(i) ' feet'])
exportgraphics(gca, sprintf('FrostPlot_%d_feet.png', i))
end
Warning: Function GEOSHOW expected DisplayType 'multipoint' to match Geometry 'polygon'. GEOSHOW is ignoring the DisplayType value.
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
Warning: Function GEOSHOW expected DisplayType 'multipoint' to match Geometry 'polygon'. GEOSHOW is ignoring the DisplayType value.
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
Warning: Function GEOSHOW expected DisplayType 'multipoint' to match Geometry 'polygon'. GEOSHOW is ignoring the DisplayType value.
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
Warning: Function GEOSHOW expected DisplayType 'multipoint' to match Geometry 'polygon'. GEOSHOW is ignoring the DisplayType value.
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
Warning: Function GEOSHOW expected DisplayType 'multipoint' to match Geometry 'polygon'. GEOSHOW is ignoring the DisplayType value.
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
  4 件のコメント
Behrooz Daneshian
Behrooz Daneshian 2023 年 2 月 20 日
Actually, the contours should rely on data from inside.Please look at the locations of weather stations on map on the attached figure. The probabilities(values shown by contour) is estimated at each weather stations. So contour lines must be estimatd based on the values there.
Walter Roberson
Walter Roberson 2023 年 2 月 20 日
At approximately x = -171 y = 57 (lower left quardrant), there appears to be a single weather station. If you restrict interpolation to be from data inside the shape, then that weather station would be surrounded by a barrier of all NaN, and when you do 2D interpolation with NaN around you, the result is NaN unless you happen to query exactly at the location of the weather station. For example if you were to ask for the reading 3 cm to the east of the weather station, the interpolated result would have to be NaN because the adjacent readings would be from outside the shape, and NaN+something is NaN.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWeather and Atmospheric Science についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by