MATLAB 2012B: The use of pcolor in combination with colorbar
Show older comments
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));
Accepted Answer
More Answers (3)
Andrew Krygier
on 7 Mar 2013
1 vote
The solution has to do with the renderer as discussed here:
If you use the command:
set(gcf, 'renderer', 'zbuffer');
you should get a better result.
There are more suggestions in the link.
Stuart Huston
on 25 Feb 2013
Try the following snippet in the editor:
generate some random x, y, and z values
nx=15;
ny=15;
x=rand(nx,1);
x=sort(x);
y=rand(ny,1);
y=sort(y);
z=rand(length(x),length(y));
% plot using pcolor()
figure
pcolor(x,y,z')
shading flat
hcb = colorbar('location','EastOutside');
now try changing the color axis
caxis([.2 .8])
On my system this gives a proper colorbar. However, now try changing nx to, say 25. In this case changing the color axis produces the spurious labels.
Nir Dahan
on 31 Aug 2015
0 votes
I have noticed that simply defining colorbar location solves the problem!
h = pcolor(UI,VI,ZI);
set(h, 'EdgeColor', 'none');
hcb = colorbar('location','eastoutside');
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!