필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Nikolay Vinnichenko
Nikolay Vinnichenko 2012년 12월 20일
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?

답변 (2개)

Jan
Jan 2012년 12월 20일
편집: Jan 2012년 12월 21일
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
Nikolay Vinnichenko
Nikolay Vinnichenko 2012년 12월 21일
Results in the same wrong colorbar height. It must be easy but no so easy.
Jan
Jan 2012년 12월 21일
See [EDITED]

댓글을 달려면 로그인하십시오.


Nikolay Vinnichenko
Nikolay Vinnichenko 2012년 12월 21일
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.

카테고리

Help CenterFile Exchange에서 Graphics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by