Plotting filled contours on top of worldmap

21 views (last 30 days)
Hi all,
I was trying to plot a filled contour on top of a worldmap but for some reason one of the values seem to be drawn all over the map as shown. I used the following code:
lat = 30:5:75;
lon = 5:5:50;
temp = [20, 18, 45, 53, 5, 44, 13, 11, 35, 48];
lat=reshape(lat,2,[]);
lon=reshape(lon,2,[]);
temp=reshape(temp,2,[]);
load coastlines
worldmap('world')
contourfm(lat,lon,temp)
geoshow(coastlat,coastlon,'color','k')
contourcbar
colormap(jet)
However the following block of code with contourm is giving a contour line with all the different colors (values) in temp plotted:
lat = 30:5:75;
lon = 5:5:50;
temp = [20, 18, 45, 53, 5, 44, 13, 11, 35, 48];
lat=reshape(lat,2,[]);
lon=reshape(lon,2,[]);
temp=reshape(temp,2,[]);
load coastlines
worldmap('world')
contourm(lon,lat,temp)
geoshow(coastlat,coastlon,'color','k')
contourcbar
colormap(jet)
Wondering how to get the same while using contourfm and a worldmap, and where I have been doing it wrong.
Thanks

Accepted Answer

Voss
Voss on 4 Jun 2022
I'm not able to see the problem as described, using the data posted.
However, check the order of the arguments you're using in contourm. You have contourm(lon,lat,temp), but contourfm(lat,lon,temp).
lat should be first in both.
lat = -85:5:85;
lon = -175:5:175;
[lat,lon] = meshgrid(lat,lon);
temp = 5+48*rand(size(lat));
figure()
load coastlines
worldmap('world')
contourfm(lat,lon,temp)
geoshow(coastlat,coastlon,'color','k')
contourcbar
colormap(jet)
figure()
load coastlines
worldmap('world')
% contourm(lon,lat,temp)
contourm(lat,lon,temp)
geoshow(coastlat,coastlon,'color','k')
contourcbar
colormap(jet)
  6 Comments
Mathan
Mathan on 4 Jun 2022
Ah ok..I get that now. Thank you so much.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!