Incorrect height of colorbar after view([0 -90])
3 views (last 30 days)
Show older comments
Hello! I have a top view of 3D surface plot, but I need to use view([0 -90]) instead of view([0 90]) in order to have reversed values order in y-axis. Surprisingly, view([0 -90]) changes my plot size and also the colorbar size. At least in some cases the colorbar height does not match the plot height. A toy example follows:
function TestViewCBar
figure('Color', 'w');
xmin=-18;xmax=3;ymin=1;ymax=7;step=0.1;
x=xmin:step:xmax;
y=ymin:step:ymax;
[K, T]=meshgrid(x, y);
Z=T.*sin(K);
hSTemp=surf(K, T, Z);
shading interp;
set(gca, 'DataAspectRatio', [1 1 1]);
axis([xmin xmax ymin ymax]);
colorbar;
view([0 -90]);
The same code with view([0 90]) provides accurate result. Any way to avoid this problem?
0 Comments
Answers (2)
Jan
on 20 Dec 2012
Edited: Jan
on 21 Dec 2012
What about calling colorbar after setting the view?
[EDITED]
Perhaps view is not a good idea. Why not setting the reverse direction, when you need the reverse direction:
set(gca, 'YDir', 'reverse');
But the position of the colorbar is actively controlled e.g. by the ResizeFcn of the figure. E.g. this cares for resizing the colorbar and for leaving space around it, when the axes is resized also. Try this:
q = colorbar;
copyobj(q, gcf);
delete(q);
Now you've created an inactive colorbar, but this is even less satisfying:
view([0 -90]);
Now the colorbar is not resized, but the main axes object fills the complete figure, such that it is displayed under the colorbar also.
There are some alternatives to colorbar in the FileExchange. It is worth to experiment with them. But they must have similar problems: Either their position reacts actively, that unwanted resizing is possible, or it does not react actively, than a wanted consideration of the space occupied by the colorbar is not possible.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!