How can I put Alaska map as a background behind my contour plots?

3 visualizaciones (últimos 30 días)
Behrooz Daneshian
Behrooz Daneshian el 17 de Feb. de 2023
Respondida: Star Strider el 15 de Mzo. de 2023
Hi all,
Using the following code I could develope countour maps showing freezing depth across the Alaska states. How can I plot these contour maps in a way that the background would be the Alaska map? The x and y axis are longitude and latitude respectively.
clear
close all
clc
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));
contourf(lon,lat,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

Respuestas (2)

the cyclist
the cyclist el 18 de Feb. de 2023
If you have the Mapping Toolbox, you can use the usamap function to make an Alaska map, and superimpose your other data on it.
  1 comentario
Behrooz Daneshian
Behrooz Daneshian el 18 de Feb. de 2023
Thank you for your reply. However, when I use usamap function and hold on together, contours will not be displayed!
clear
close all
clc
load('POFDE.mat');
data = cell2mat(POFDE);
[lat,lon] = meshgrid(unique(data(:,1)),unique(data(:,2)));
for i = 1:(size(data, 2)-2)
figure
usamap("Alaska")
states = readgeotable("usastatehi.shp");
row = states.Name == "Alaska";
alaska = states(row,:);
geoshow(alaska,"FaceColor",[0.3 1.0, 0.675])
textm(alaska.LabelLat,alaska.LabelLon,alaska.Name, ...
"HorizontalAlignment","center")
hold on;
I = scatteredInterpolant(data(:,[1 2]), data(:,i+2));
contourm(lon,lat,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))
hold off
end

Iniciar sesión para comentar.


Star Strider
Star Strider el 15 de Mzo. de 2023
You have ‘lat’ and ‘lon’ reversed in the first two arguments to the contourm call.
Reversing them —
% clear
% close all
% clc
% load('POFDE.mat');
load(websave('POFDE','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1299285/POFDE.mat'))
data = cell2mat(POFDE);
[lat,lon] = meshgrid(unique(data(:,1)),unique(data(:,2)));
for i = 1:(size(data, 2)-2)
figure
usamap("Alaska")
states = readgeotable("usastatehi.shp");
row = states.Name == "Alaska";
alaska = states(row,:);
geoshow(alaska,"FaceColor",[0.3 1.0, 0.675])
textm(alaska.LabelLat,alaska.LabelLon,alaska.Name, ...
"HorizontalAlignment","center")
hold on;
I = scatteredInterpolant(data(:,[1 2]), data(:,i+2));
contourm(lat,lon,I(lat,lon), 'LineWidth',2,'ShowText','on')
colormap(turbo)
colorbar
title(['The probability of frost depth exceedance of \Omega_{\delta} = ' num2str(i) ' feet'])
% exportgraphics(gca, sprintf('FrostPlot_%d_feet.png', i))
hold off
end
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
.

Categorías

Más información sobre Geographic Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by