How to plot a 2D matrix ( Lon, Lat and Data ) on a map with countour
7 views (last 30 days)
Show older comments
Anthony Cazin-Bourguignon
on 9 Nov 2020
Edited: Cris LaPierre
on 10 Nov 2020
Hi guys,
I am currently working on a project and would like to display data contained in a matrix on a map.
The matrix looks like this:

It is 208*261.
For the moment I would just like to display this data with a colorbar on the target location of the world map (North Sea). In a second step, I would like to display the countries on the map in order to have only the ocean data.
I don't know if this is possible.
Thank you
0 Comments
Accepted Answer
Cris LaPierre
on 9 Nov 2020
Edited: Cris LaPierre
on 10 Nov 2020
It's possible, it's just a matter of formatting the data. However, you'll likely find most are not willing to transcribe your spreadsheet data from an image. If you want to share it, you can attach it using the paperclip icon.
I would try using readmatrix to load the data into MATLAB and then extract the data and plot it. Generic code might be this (untested)
data = readmatrix(excelData.xlsx);
Lon = data(2:end,1);
Lat = data(1,2:end);
Data = data(2:end,2:end)
contourm(Lat,Lon,Data')
2 Comments
Cris LaPierre
on 10 Nov 2020
Edited: Cris LaPierre
on 10 Nov 2020
Let me say that I'm also new to mapping. Everything I'm coming up with I'm learning from the documentation.
First, be mindful of your data, particularly what is lat vs lon. Spot check your plots to make sure the data is displaying correctly (something that got me a couple times).
Here are a few different approaches. First, plot your data as contour lines using contourm.
% Import the data
data = readmatrix("matriceLCOE.xlsx");
Lon = data(2:end,1);
Lat = data(1,2:end);
Data = data(2:end,2:end)'; % Transpose so rows=Lat, col=Lon
% Create world map zoomed to extents of data. Any land will show as green
worldmap([-5 10],[50 65])
land = shaperead('landareas.shp', 'UseGeoCoords', true);
geoshow(land, 'FaceColor', [0.15 0.5 0.15])
% Add a contour map of the data. Legend shows countour values
[c,h]=contourm(Lat,Lon,Data);
clegendm(c,h,-1)
Another approach might be to use your actual data to color the map rather than relying on contour lines. This might be helpful because, given the range of values in your data, some of the subtle changes are not appearing in a contour plot. I used georefcells to create a geographic coordinates referencing object.
% Create a referencing object. Because of the way the data is organized,
% it was necessary to specify the "startFrom" options.
latlim = [min(Lat) max(Lat)];
lonlim = [min(Lon) max(Lon)];
rasterSize = size(Data);
R = georefcells(latlim,lonlim,rasterSize,"ColumnsStartFrom","north","RowsStartFrom","east");
figure
worldmap(Data,R)
geoshow(Data,R,'DisplayType','texturemap')
colormap cool
colorbar
Finally, it might be possible to visualize your data without using a map at all. The scaling (lat vs lon spacing) is lost, and the axes aren't pretty, but the visualization is actually what got me to pursue the second option above. This is a heatmap.
figure
h=heatmap(fliplr(Data),"GridVisible","off",...
"XDisplayLabels",Lon,"YDisplayLabels",Lat,...
"XLabel","Longitude","YLabel","Latitude");
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


