pcolor/m_pcolor cannot create world map correctly

Hello all,
I have an issue to create world mean temperature map correctly with pcolor/m_pcolor. There are strips on the map created. Please see the first map.
h1 = pcolor(lon,lat,statTa(:,:,i)); set(h1,'edgecolor','none'); colorbar;
When I use imagesc, it shows pretty well. Please see the second map. But I think I prefer to use pcolor/m_pcolor to create map since they are more powerful on creating maps. Please help me on what happened when I was using pcolor here. Thank you very much!
h2 = imagesc(lon,lat,statTa(:,:,i)); set(gca,'ydir','normal'); colorbar;

11 commentaires

It might be possible that the lat,lon data is not uniform and pcolor is somehow trying to draw a line between non uniform grid while imagesc is not.
Is the data uniform? Also what version of MATLAB is this?
Can you upload your lat,lon grids?
Rong Yu
Rong Yu le 5 Juin 2015
The matlab version is R2014a. The data is GLDAS 0.25 degree GRIB format data. I attached lat, lon grids to this comment.
I cannot reproduce the problem. It looks like your oceans are set to NaN, so I'm doing the same below. I resize the dataset before using my landmask function because landmask is quite slow for large grids.
load lonLat
% Created gridded lat/lon:
[long,latg] = meshgrid(lon,lat);
% Create temperature-like data:
T = 250+50*cosd(latg) + 5*sind(long) + rand(size(latg));
% Set oceans to NaN:
scale = 5;
ocean = ~landmask(imresize(latg,1/scale),imresize(long,1/scale));
T(imresize(ocean,scale)) = NaN;
% Plot with pcolor:
h1 = pcolor(lon,lat,T);
set(h1,'edgecolor','none');
colorbar
Thank you so much, Chad! I tried again, but the same problem still showed up. I attached the temperature data here. Could you help me to try it again? Thank you so much!!! My code is as below
load monthTa1
h1 = pcolor(lon,lat,monthTa1);
set(h1,'edgecolor','none')
colorbar;
Very strange. It works just fine for me in R2012b.
load lonLat
load monthTa1
h1 = pcolor(lon,lat,monthTa1);
set(h1,'edgecolor','none')
colorbar;
colormap(brewermap(1024,'Reds'))
set(gca,'color',rgb('ocean blue'))
borders('countries','color',.2*[1 1 1],'nomap')
Above I used brewermap because the default jet colormap is a bit garish, and rgb to get ocean blue. National borders are plotted with borders
Have you tried gridding your lat/lon arrays? Syntax would be
[long,latg] = meshgrid(lon,lat);
pcolor(long,latg,Z)
Not sure if gridding your lat/lons will fix the problem, but give it a shot.
Rong Yu
Rong Yu le 8 Juin 2015
Thank you so much, Chad!!!
I tried the gridding you suggested and the fig showed the same, but I found out the figure looks normal if I saved it as bmp. Please see the attached. I cannot understand what's wrong with my matlab ... It is frustrating.
Thank you for suggesting to use brewermap, rgb, and borders!!! They are amazing at making maps!!!
The .bmp amd the .fig both look good for me. To be clear, the map looks good on your machine after you save it, but not in the Matlab figure window? If this is the case, try switching renderers. Type
set(gcf,'renderer','opengl')
If that doesn't work, try
set(gcf,'renderer','painters')
and if that doesn't work, try
set(gcf,'renderer','zbuffer')
Rong Yu
Rong Yu le 9 Juin 2015
Chad, thank you thank you soooo much!!! The 2nd and 3rd ones work! Fantastic!
What version of MATLAB are you using? That looks like an issue that was fixed in R2014b. Is your version older than that, or newer?
Rong Yu
Rong Yu le 9 Juin 2015
Hi Mike, it is R2014a.

Connectez-vous pour commenter.

 Réponse acceptée

This question has been answered in the comments above, but in case anyone else runs into this problem again, here's an easier-to-find version of the solution. This is a rendering issue in Matlab versions pre-R2014b. Type
set(gcf,'renderer','opengl')
If that doesn't work, try
set(gcf,'renderer','painters')
and if that doesn't work, try
set(gcf,'renderer','zbuffer')

1 commentaire

Rong, if this solution worked for you, please click "Accept this answer" so it'll get top-posted.

Connectez-vous pour commenter.

Plus de réponses (1)

Chad Greene
Chad Greene le 8 Juin 2015

0 votes

I see that when you use pcolor your axis values are not lat,lon values. Looks like linear indices of rows and columns. Are you sure you're plotting lat and lon?

2 commentaires

Rong Yu
Rong Yu le 8 Juin 2015
A good catch! I tried to plot lon,lat one and the one without lon, lat, but the figures have the same problem. Thank you so much for helping me with this!
Rong Yu
Rong Yu le 8 Juin 2015
Hi Chad,
You are so excellent at matlab coding! Do you mind sharing your tips and recommending some good matlab coding resources? Thank you :)))

Connectez-vous pour commenter.

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by