In 3D plot, how do I set the vertical axis to be y-axis down, z-axis forward and x-axis right?

My hybrid 3D curves and images were drawn together, and I initially succeeded in drawing the result I wanted below, but the only thing missing was the y-axis and z-axis orientation. how do I set the vertical axis to be y-axis down, z-axis forward and x-axis right?(i.e. the physical coordinate system of the camera),your answer would be great appreciately!
%% x,y,z axis is located origin
% https://ww2.mathworks.cn/matlabcentral/answers/386936-change-x-y-z-axes-position-in-a-3d-plot-graph
hAxis = gca;
hAxis.XRuler.FirstCrossoverValue = 0; % X crossover with Y axis
hAxis.XRuler.SecondCrossoverValue = 0; % X crossover with Z axis
hAxis.YRuler.FirstCrossoverValue = 0; % Y crossover with X axis
hAxis.YRuler.SecondCrossoverValue = 0; % Y crossover with Z axis
hAxis.ZRuler.FirstCrossoverValue = 0; % Z crossover with X axis
hAxis.ZRuler.SecondCrossoverValue = 0; % Z crossover with Y axis
hAxis.Parent.Color=[1,1,1];
view(3);
box off;grid off;hold on;
%% space curve
t = -300:.1:400;
y = 200*sin(t/30);
z = 200*ones(size(t));
plot3(hAxis,t,y,z)
axis([-300,600,-300,600,0,200])
%% space image
img = imread("peppers.png");
image(hAxis,img)
%% adjust to show axes label
xlabel("x");ylabel("y");zlabel("z")
hAxis.YDir="reverse";
hAxis.ZDir = "reverse";
hAxis.XAxis.Label.Position=[hAxis.XLim(end),0,0];
hAxis.YAxis.Label.Position=[0,hAxis.YLim(end),0];
hAxis.ZAxis.Label.Position=[0,0,hAxis.ZLim(end)];
hAxis.LabelFontSizeMultiplier=3;
NOTES:
The following rendering should be oriented like the red arrow I drew by hand,not black,(The default rotation has the z-axis facing forward instead of the default z-axis vertical, just like matlab's built-in functions pcshow, pcplayer, etc. have the verticalAxis property to control the axis orientation)

6 Comments

So what's wrong? Looks like the orientation described to me...what am I missing?
what I need is a 3D plot with the z-axis facing forward, the y-axis vertically down and the x-axis facing right! But this image has the z-axis facing down and the y-axis facing back, which is not what I was expecting
Use the rotate3d tool to move the axes orientation until it looks good. The azimuth and elevation are shown as you rotate. Once it's ok, you can use those azimuth and elevation values in view() to reproduce the orientation programmatically.
@Voss I tried the rotate3d tool or set hAxis.CameraUpVector=[0,1,0], which also did not achieve the result I expected. When using the rotate3d tool interactively, the default Z-axis is vertical again
When I add pcshow after the above code, it turns out the way I expect it to, even after rotating with the roate3d tool, it doesn't change to the default z-axis up, the only thing that changes is the background colour to black
hold on;
ax = pcshow([1,1,1],'black',VerticalAxis="Y")
hold off;
hi,all @dpb @Voss ,of course, the above program is not an "elegant" approach,and if there is a better way, I would like to suggest it for discussion

Sign in to comment.

Answers (0)

Products

Release

R2022a

Asked:

on 19 Aug 2022

Commented:

on 22 Aug 2022

Community Treasure Hunt

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

Start Hunting!