How to overlap several maps?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jonathan Demmer
le 15 Mar 2022
Commenté : Jonathan Demmer
le 17 Mar 2022
Hi all,
I wrote two codes (code 1 and code 2) below to produce the pictures attach within htis question. I would like to add on th figure showing the vessel density (vessel density.png file; code 1), the limit of the coastal area of the United Kingdom (and associated islands) and Ireland using M_map (also attached here: UK.jpg; code 2). does someone how can I write one code to have both on it? Also, if someone knows how to fill the land (inside the coastal limit) in white to make it look better that would be also great.
Regards
%% Code 1
% assign the path to your working directory:
cd ('E:\Data_emodnet_fisheries\Vessel_density\');
load Average.mat % Matrice representing the positon of boat in the sea
imshow(Average,Colormap=turbo);
limits = [0,3];
c = colorbar;
set(gca,'clim',limits([1,end]));
c.Label.String = 'Vessel density (h/m2/month)';
saveas(gcf,'Vessel_density.png')
%% Code 2
% assign the path to your working directory:
cd ('E:\publi\Waiting-room\Matt_paper_hydrogen\figure_Matt\new\gshhg-bin-2.3.7(1)\');
% add path to TelemacTolls functions (i.e. to read in telemac files into MATLAB):
addpath ('C:\Matlab_download\m_map1.4\m_map\');
workingFolder = tempdir;
latlim = [48 63];
lonlim = [-12 3];
S = gshhs('gshhs_h.b', latlim, lonlim);
levels = [S.Level];
L1 = S(levels == 1);
figure
plot ([L1.Lon],[L1.Lat], '-b');
xlim([-11 3]);
ylim([49 61]);
0 commentaires
Réponse acceptée
Kevin Holly
le 15 Mar 2022
Modifié(e) : Kevin Holly
le 15 Mar 2022
You could edit the colormap to make the land white.
figure
image
colorbar
colormap turbo
figure(2)
image
colorbar
cmap = turbo;
cmap(1:4,:)=ones(4,3);
colormap(cmap)
In your case, you can do the following:
cmap = turbo;
cmap(1:4,:)=ones(4,3);
imshow(Average,Colormap=cmap);
You may need to adjust the range in which the color is white ([1 1 1]).
As for overlaying the plot on the image. You could use "hold on" as such:
hold on
plot ([L1.Lon],[L1.Lat], '-b');
xlim([-11 3]);
ylim([49 61]);
The resolution of the image (x pixels vs y pixels) and the coordinates of the plot (latitude vs longitude range) may not match. You may need to scale it.
3 commentaires
Kevin Holly
le 16 Mar 2022
If you are having difficulties lining up the axes. You could create two different axes and make the background and axes of the axes with the plot invisible.
ax1 = axes;
img = image;
colorbar
cmap = turbo;
cmap(1:4,:)=ones(4,3);
colormap(cmap)
ax2 = axes;
plot(50*rand(7,7))
ax2.Color='none';
ax2.Position = ax1.Position;
axis off
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Orange dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!