How can I plot contour lines on the generated map?
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Behrooz Daneshian
il 20 Feb 2023
Commentato: Walter Roberson
il 20 Feb 2023
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 Commento
Walter Roberson
il 20 Feb 2023
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.
Risposta accettata
Voss
il 20 Feb 2023
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
4 Commenti
Walter Roberson
il 20 Feb 2023
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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Contour Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!