Set y-axis as vertical when plotting in 3d

By default, the 'plot3' function assumes that Z-data denotes vertical data. For example, if I were plotting motion capture data of, say, a subject's right foot - plot3(rFootX, rFootY, rFootZ) - it would plot the 'rFootZ' data as the vertical position of the foot.
Is there a way to set 'plot3' so that it uses Y as the default vertical axis? That is, if my motion capture system outputs the vertical position of a subjects' right foot as 'rFootY,' can I set things up so that plotting 'plot3(rFootX, rFootY, rFootZ)' displays the data correctly (with Y pointing up)?
Up until now, I have been using a little helper function to get things to plot with Y pointing up:
function plot3y(x,y, z,varargin) plot3(x,-z,y,varargin{:})
But this gets VERY confusing when trying to manipulate the resulting plots using the default Matlab functions like "axis" and "surface," as these assume that the Z-axis is the vertical.
I have also played around with using camroll (specifically, 'camroll(-90)'), but this tends to get screwy when I start adjusting the the viewpoint (the camera still tries to rotate around a Z-vertical axis).
tl;dr - I'm looking for some setting that I adjust that will set the Y-axis as the default vertical when using 'plot3'

1 commentaire

Yi Wan
Yi Wan le 22 Oct 2018
Hi John,
Did you find the final solution other than using camup?

Connectez-vous pour commenter.

 Réponse acceptée

Mike Garrity
Mike Garrity le 19 Oct 2015
Perhaps you just want to set the CameraUpVector ?
xlabel('X')
ylabel('Y')
zlabel('Z')
box on
view(3)
camup([0 1 0])

4 commentaires

Blake Andersen
Blake Andersen le 15 Juin 2018
Sorry, my comment below should have been here.
Setting CameraUpVector, then changing where the axis are displayed could work, but it doesn't survive rotation.
Hank
Hank le 3 Mar 2020
Modifié(e) : Hank le 3 Mar 2020
Blake, were you able to find a way to get CameraUpVector to survive rotation?
I tried setting CameraUpVectorMode to 'manual', but this also gets reset to auto upon rotation.
>>set(gca,'CameraUpVector',[1 0 0],'CameraUpVectorMode','manual')
>> gca
Axes with properties:
...
CameraUpVector: [1 0 0]
CameraUpVectorMode: 'manual'
...
>> % performs rotation on figure
>> gca
Axes with properties:
...
CameraUpVector: [0 0 1]
CameraUpVectorMode: 'auto'
...
Eva Herbst
Eva Herbst le 20 Mai 2021
I found that setting the camera view in the code before the camup worked.
Still doesn't work if you want to interact with the figure but if you just need one angle for an image then this works well.
Another workaround is recoloring the axes and then rotating all of your data accordingly, but this results in messy code. Solves the interaction problem though.
Alec Jacobson
Alec Jacobson le 18 Août 2022
Still no solution that maintains during interaction?

Connectez-vous pour commenter.

Plus de réponses (4)

Pierce
Pierce le 17 Oct 2019
Modifié(e) : Pierce le 17 Oct 2019
Unfortunately, I couldn't find a soluition based on axis manipulation so I ended up modifying the data and relabelling the axis to achieve the orientation I wanted.
iReorder = [-1 3 2]; % Invert X axis, and swap Y + Z axis. Unity to Matlab transformation
iInvert = find(iReorder < 0); % Column indicies to invert
iReorder = abs(iReorder); % Column indicies to reorder
Pxyz; % Orignal x y z data
Pxyz = Pxyz(:,iReorder); % Reorder x y z data to x z y
Pxyz(:,iInvert) = -Pxyz(:,iInvert); % Invert data to -x z y
plot3(Pxyz(:,1),Pxyz(:,2),Pxyz(:,3),'.b')
xlabel('x');
ylabel('z');
zlabel('y');
Optionaly, the axis can be inverted instead of inverting the data.
h.axes = axes;
set(h.axes,'XDir','reverse')
Blake Andersen
Blake Andersen le 15 Juin 2018

0 votes

This answer only works if you're happy switching from a right handed coordinate system to left. I want a consistent way to plot data in the system that is standard for my industry: +X -> right +Y -> up +Z -> forward Simply changing the labels and transforming the data results in the x axis of the plot displaying the opposite of actual.
There are a string of hacks that I have been doing to cover this up, but I just want to change the orientation of the plot.
Pierce
Pierce le 14 Déc 2018
I'm trying to do the same but haven't quiet found a solution outside of reordering my input data.
setting the camera to [0 1 0] is a starting point, but as you say it doesn't survive rotation operations.
setting the direction of X axis to reverse can help
% Unity coordinate space
set(h.axes,'CameraUpVector',[0 1 0]) % Set Y axis as vertical
set(h.axes,'XDir','reverse') % Reverse the x axis
MCH
MCH le 17 Oct 2019
Modifié(e) : MCH le 17 Oct 2019

0 votes

Has anyone found a solution? This is quite frustrating and I am having to apply hacks when switching from 3D to 2D input files. I just want to change the orientation of the plot. How can this be so hard?

1 commentaire

Matthew Galles
Matthew Galles le 14 Oct 2020
Modifié(e) : Matthew Galles le 14 Oct 2020
Just wasted a few hours trying to sort this out.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by