Incorrect height of colorbar after view([0 -90])

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

Answers (2)

Jan
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.
  2 Comments
Nikolay Vinnichenko
Nikolay Vinnichenko on 21 Dec 2012
Results in the same wrong colorbar height. It must be easy but no so easy.

Sign in to comment.


Nikolay Vinnichenko
Nikolay Vinnichenko on 21 Dec 2012
Thanks, Jan. set(gca, 'YDir', 'reverse') really solves my problem. I've just forgot about this property.
In fact, colorbar does resize with view command application and so does the plot (which is natural). What seems strange is that view([0 -90]), though absolutely symmetrical to view([0 90]), provides different plot size and colorbar size, which does not match to it. Unfortunately, I don't know how colorbar 'Position' is derived from the plot parameters, and what are the parameters affecting the plot size in pixels. Axes 'Position' does not change.

Categories

Find more on Graphics 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!