MATLAB Answers

Strange colorbar behaviour (must be a bug?)

7 views (last 30 days)
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

Accepted Answer

Titus Edelhofer
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
  1 Comment
Gabriel Rosser
Gabriel Rosser on 9 Sep 2011
Thanks Titus, you're right that fixes it. It's not a perfect solution because it means you can't use transparency, but I have learnt to accept that Matlab has some limitations!

Sign in to comment.

More Answers (1)

Titus Edelhofer
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
  1 Comment
Gabriel Rosser
Gabriel Rosser on 9 Sep 2011
Again, thanks - in fact, this was the workaround I used after posting my question and before your answer about the renderer!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!