Problem setting axes position when using "camva" function

3 views (last 30 days)
Hello, I've encountered a few problems when using the "camva" function. One of those problems is that the position of axes behaves very strangely.
1. When using camva the axes changes its size, but when requesting the new position, it says that the position is the same. 2. When trying to change the width of the axes (third position entry), the axes moves right instead.
Here is a code example that reproduces these two issues (see comments):
if true
% code
end
X = rand(10);
Y = rand(10);
Z = rand(10);
figure(1)
plot3(X,Y,Z,'o')
set(gca, 'position', [0.5 0.55 0.3 0.3])
camva(5); % the axes became larger
newPos = get(gca, 'position'); % newPos equals to the previous position ([0.5 0.55 0.3 0.3]) even though the
position has actually changed
pause;
set(gca, 'position', [0.5 0.55 0.4 0.3]) % the axes should grow wider without moving, but it moves right
instead.
Can you please help me with this issue. Thank you very much, Alexandra.
  2 Comments
Adam
Adam on 22 Jun 2017
I've never used camva and almost never mess around with the camera as it can get complicated and I've never learned all I need to to properly understand it.
But, I'm fairly sure i am correct in saying that your axes do not move when you give a camva instruction so newPos in your code is as it should be.
The camera is what has moved, which means the viewpoint is now different, but the axes themselves still have their same position. What this position is relative to, with the new view angle is not immediately intuitive though.
Alexandra Gilinsky
Alexandra Gilinsky on 22 Jun 2017
Hi Adam, thank you very much for your answer! What I actually like to do is to fix my "screen" and camera field of view, and "travel" with the camera such that my screen will stay in its place (like watching tv). I don't understand how it is possible when the position of the axes behaves unexpectedly. In particular, when the axes visually changes its position but says it doesn't (I agree with you that the axes should stay in its place when changing camera field of view, but it visually changes). Also, the position of the camera hasn't changed, only its field of view (can be verified using campos and camtarget). There should be a way to do that in Matlab. It seems to me that there is an issue with the camva function. Is there any way to address this question to someone who worked on that function?
Thank you very much, Alexandra.

Sign in to comment.

Answers (2)

Jan
Jan on 22 Jun 2017
1. When using camva the axes changes its size, but when requesting the new position, it says
that the position is the same.
Exactly. This is expected when you change the view angle of the camera. It is like using the zoom of a camera: The camera and the object stay at the same position, but the apparent size of the object changes.
2. When trying to change the width of the axes (third position entry), the axes
moves right instead.
This can happen, if you have a distored view to the object already. 3D geometry is tricky. You have the DataAspectRatio, Matlab scales the axes with the AutoFill-methods to the available space, the view angle, camera-up vector and position of the camera as well as the target position. It is not surprising that changing some parameters change the view in an unexpected, but exactly and correctly defined way.
  1 Comment
Alexandra Gilinsky
Alexandra Gilinsky on 22 Jun 2017
Thank you very much Jun for your answer. Regarding 1: Exactly like you said, I do expect the zoom effect (camera and the object stay at the same position, but the apparent size of the object changes). What I don't expect is that the axes will become larger (which is like my screen). And if the axes does become larger, I would expect the position reflect that.
Regarding 2: What I actually like to do is to fix my "screen" and camera field of view, and "travel" with the camera such that my screen will stay in its place (like watching tv). I don't understand how it is possible when the position of the axes behaves unexpectedly.

Sign in to comment.


Niel Crews
Niel Crews on 10 Mar 2021
The axes actually IS at the original size when this happens. However, the default is for objects to overflow the axes bounds when using these camva, camtarget, campos controls. To prevent this overflow, set the ClippingStyle property of the axes to 'rectangle'.
set(gca, 'ClippingStyle','rectangle')

Community Treasure Hunt

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

Start Hunting!