MATLAB: MATLAB 2012B: The use of pcolor in combination with colorbar

colorbar pcolorImage Processing Toolbox

Hi all,
I am trying to make a nice figure with pcolor in combination with colorbar. Running the code shown below results in a figure with way too many tick labels (multiple and double overlapping) on the x-axis and colorbar. Is there a nice solution for this? I have to make quite a number of these graphs (100+). Any idea is welcome!
Best regards, Simon
The code (please try to run it, the result is quite astonishing):
minu = -6;
maxu = 6;
U = 2*(rand(1,1000)+1);
V = 6*rand(1,1000);
Z = 2*(rand(1,1000)-0.5);
Urange = linspace(min(U),max(U),100);
Vrange = linspace(min(V),max(V),100);
[UI,VI] = meshgrid(Urange,Vrange);
ZI = griddata(U,V,Z,UI,VI,'cubic');
h = pcolor(UI,VI,ZI);
set(h, 'EdgeColor', 'none');
hcb = colorbar;
colormap(hsv(256));
caxis([minu, maxu]);
colormap(flipud(colormap));

Best Answer

First of all, I'm not sure why you're using pcolor() instead of imshow() or image(). Do you know that you lose a row and column of your data if you do that? And your data point is actually the place where the lines (which you turned off) cross, not the whole colored pixel/square/tile like you'd think, though it seems that way if you use "flat" shading (if you don't use flat shading, you'll probably be very surprised). So that's why I never use pcolor().
Also, I get 7 colorbar labels and 9 axis marks. You can use set(gca, 'XTick',.... to set up whatever tick marks you want.
Try running my code to see how it looks with imshow(). You'll get all your data (no missing row and column) and you'll get full range of the colormap.
minu = -6;
maxu = 6;
U = 2*(rand(1,1000)+1);
V = 6*rand(1,1000);
Z = 2*(rand(1,1000)-0.5);
Urange = linspace(min(U),max(U),100);
Vrange = linspace(min(V),max(V),100);
[UI,VI] = meshgrid(Urange,Vrange);
ZI = griddata(U,V,Z,UI,VI,'cubic');
h = pcolor(UI,VI,ZI);
set(h, 'EdgeColor', 'none');
hcb = colorbar;
colormap(hsv(256));
caxis([minu, maxu]);
colormap(flipud(colormap));
% Enlarge figure to full screen.

set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Code added by Image Analyst
figure;
imshow(ZI, [], 'InitialMagnification', 800);
colormap(jet(256));
colorbar;
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
Related Question