2
$\begingroup$

I have, as an example, a 3D plot showing some data:

data = {{100, 0, 0}, {0, 80, 0}, {0, 0, 60}}

ListPointPlot3D[data, PlotStyle -> {PointSize[0.04]}, BoxRatios -> {100, 80, 60}, 
  Boxed -> True, Axes -> True, AxesLabel -> {"x", "y", "z"}, 
  ViewProjection -> "Orthographic", AxesEdge -> {{-1, -1}, {-1, -1}, {-1, -1}}, 
  PlotRange -> {{0, 100}, {0, 80}, {0, 60}}]

normal

This corresponds to a right-handed coordinate system. (See also this question.)

I want to exchange the $y$ and $z$ axes to switch to a left-handed coordinate system.

Manually, I can do:

datanew = {{100, 0, 0}, {0, 60, 0}, {0, 0, 80}};

ListPointPlot3D[datanew, PlotStyle -> {PointSize[Large]}, BoxRatios -> {100, 60, 80}, 
  Boxed -> True, Axes -> True, AxesLabel -> {"x", "z", "y"},
  ViewProjection -> "Orthographic", AxesEdge -> {{-1, -1}, {-1, -1}, {-1, -1}}, 
  PlotRange -> {{0, 100}, {0, 60}, {0, 80}}]

Does a built-in solution exist to exchange two axes, whereby the $y$ and $z$ data are exchanged as well as the axes labels?

exchanged

$\endgroup$
4
$\begingroup$
lpp3d = ListPointPlot3D[data, PlotStyle -> {PointSize[0.04]}, 
   BoxRatios -> {100, 80, 60}, Boxed -> True, Axes -> True, 
   AxesLabel -> {"x", "y", "z"}, 
   ViewProjection -> "Orthographic", 
   AxesEdge -> {{-1, -1}, {-1, -1}, {-1, -1}}, 
   PlotRange -> {{0, 100}, {0, 80}, {0, 60}}]

newoptions= Flatten[{(# -> (# /. Options[lpp3d])[[{1,3,2}]])&/@ 
   {BoxRatios, AxesLabel, BoxRatios, PlotRange}, 
   FilterRules[Options[lpp3d], {Boxed, Axes, ViewProjection, AxesEdge}]}];

ListPointPlot3D[data[[All, {1,3,2}]], PlotStyle -> {PointSize[0.04]}, newoptions]

enter image description here

Alternatively,, post-process to change the graphics primitives and options:

f = #[[{1, 3, 2}]]&;
lpp3d /. { Point[x_] :> Point[f/@x], 
  Rule[o: Alternatives[BoxRatios, AxesLabel, BoxRatios, PlotRange], v_] :> Rule[o, f @ v]}

same picture

$\endgroup$
6
$\begingroup$

This could be a good place for some pattern matching. To switch the data around:

data = {{100, 0, 0}, {0, 80, 0}, {0, 0, 60}}; 
datanew = data[[#]] /. {x_, y_, z_} -> {x, z, y} & /@ Range[Length[data]]

{{100, 0, 0}, {0, 0, 80}, {0, 60, 0}}
$\endgroup$
1
$\begingroup$

The simplest way to accomplish this is to set ViewVertical appropriately:

data = {{100, 0, 0}, {0, 80, 0}, {0, 0, 60}};
ListPointPlot3D[data, AxesEdge -> {{-1, -1}, {-1, -1}, {-1, -1}}, 
                AxesLabel -> {"x", "y", "z"}, BoxRatios -> {100, 80, 60}, 
                PlotRange -> {{0, 100}, {0, 80}, {0, 60}}, 
                PlotStyle -> PointSize[0.04], ViewProjection -> "Orthographic", 
                ViewVertical -> UnitVector[3, 2]]

flipped axes

$\endgroup$
0
$\begingroup$

This is a solution from Wolfram:

data = {{100, 0, 0}, {0, 80, 0}, {0, 0, 60}};

rhListPointPlot3D[data_, opts : OptionsPattern[ListPointPlot3D]] := 
 Module[{newDat = data /. {x_?NumericQ, y_?NumericQ, z_?NumericQ} :> {x, z, y}}, 
 ListPointPlot3D[newDat, opts]]

rhListPointPlot3D[data, PlotStyle -> {PointSize[Large]}, BoxRatios -> {100, 60, 80}, 
 Boxed -> True, Axes -> True, AxesLabel -> {"x", "z", "y"}, 
 ViewProjection -> "Orthographic", AxesEdge -> {{-1, -1}, {-1, -1}, {-1, -1}}, 
 PlotRange -> {{0, 100}, {0, 60}, {0, 80}}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.