Strange colorbar behaviour (must be a bug?)
5 views (last 30 days)
Show older comments
Hi All, I have discovered some very strange behaviour when plotting a surface using pcolor and adding a colorbar (Matlab 2011a, Linux). If the values shown in the plot are sufficiently large that Matlab displays them as "a times 10^b", the "\times 10^b", it seems impossible to remove the floating "\times 10^b" part of the ytick labels.
I have produced a minimal working example here:
[X Y] = meshgrid(linspace(0,1,100));
Z = 8e3*rand(size(X))+8e3;
% default colorbar
figure;
pcolor(X,Y,Z);
colorbar();
% define custom y ticks
YTicks = {'a','b','c'};
% colorbar with ticks changed
figure;
pcolor(X,Y,Z);
hCol=colorbar();
set(hCol,'YTickLabelMode','manual');
set(hCol,'YTickLabel',YTicks);
The default colorbar appears with an ugly \times 10^4 at the top (I use font size 14, so it actually disappears off the top of the figure). In the second example, I manually specify the tick labels, which should overwrite the old ones... but the \times 10^4 doesn't disappear, which makes no sense at all!
This is a bug, right? There can't be any use case where this would be desirable?
Anyway, anyone know how to remove it?
Thanks for your help.
Gabriel
0 Comments
Accepted Answer
Titus Edelhofer
on 9 Sep 2011
Hi Gabriel,
this is a problem with the OpenGL rendering this image. In this case using another renderer should solve the problem:
set(gcf,'Renderer', 'zbuffer')
Titus
More Answers (1)
Titus Edelhofer
on 9 Sep 2011
Hi Gabriel,
there is in fact another work around you can use: scale your axes values. If you have e.g.
x=1:100; y=1:100;
[X,Y]=meshgrid(x,y);
Z = X.*X+Y.*Y;
surf(X,Y,Z)
you could do something like
x=1:100; y=1:100;
[X,Y] = meshgrid(x,y);
Z = X.X+Y.*Y;
surf(X/100, Y/100, Z)
No problem, since you set the ticks yourself anyway ...
Titus
See Also
Categories
Find more on Colormaps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!