Group Abstract Group Abstract

Message Boards Message Boards

0
|
17 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to convert the 3D rectangular coordinate axes in the figure to this standard form?

Posted 13 hours ago
U = Tuples[{-2, -1, 1, 2}, 3];

pointsByZ = GroupBy[U, Last];

colors = {-2 -> Red, -1 -> Blue, 1 -> Green, 2 -> Orange};

Graphics3D[
 Table[{z /. colors, PointSize[0.03], 
   Point[pointsByZ[z]]}, {z, {-2, -1, 1, 2}}], Axes -> True, 
 AxesLabel -> {"X", "Y", "Z"}, Boxed -> False, 
 Ticks -> {{-2, -1, 0, 1, 2}, {-2, -1, 0, 1, 2}, {-2, -1, 0, 1, 2}}, 
 BoxRatios -> {1, 1, 1}, PlotRange -> {{-3, 3}, {-3, 3}, {-3, 3}}, 
 PlotLabel -> Style["64 points colored by Z layer", Bold, 14], 
 ImageSize -> {600, 600}, 
 Epilog -> 
  Inset[Grid[{{Graphics[{Red, Disk[]}, ImageSize -> 10], 
      "z = -2"}, {Graphics[{Blue, Disk[]}, ImageSize -> 10], 
      "z = -1"}, {Graphics[{Green, Disk[]}, ImageSize -> 10], 
      "z = 1"}, {Graphics[{Orange, Disk[]}, ImageSize -> 10], 
      "z = 2"}}], {Right, Top}, {Right, Top}]]

The corresponding graph produced by the foregoing code is presented as follows:

enter image description here

The axes of the default spatial rectangular coordinate system generated by the preceding code are arranged on one side of the graph. Please advise how to revise the code to render the axes in the conventional form illustrated below.

enter image description here

POSTED BY: Bill Blair
3 Replies

Apart from Gianlucas suggestion using AxesOrigin, you are working with `Graphics3D´ and here you can virtually do just anything, e.g. simply adding arrows along axis:

Graphics3D[{Table[{z /. colors, PointSize[0.03], 
    Point[pointsByZ[z]]}, {z, {-2, -1, 1, 2}}], Thick, 
  Arrow[{{-3, 0, 0}, {3, 0, 0}}], Arrow[{{0, -3, 0}, {0, 3, 0}}], 
  Arrow[{{0, 0, -3}, {0, 0, 3}}]}, Axes -> True, 
 AxesLabel -> {"X", "Y", "Z"}, Boxed -> False, TicksStyle -> Large, 
 Ticks -> {{-2, -1, 0, 1, 2}, {-2, -1, 0, 1, 2}, {-2, -1, 0, 1, 2}}, 
 BoxRatios -> {1, 1, 1}, PlotRange -> {{-3, 3}, {-3, 3}, {-3, 3}}, 
 PlotLabel -> Style["64 points colored by Z layer", Bold, 14], 
 ImageSize -> {600, 600}, 
 Epilog -> {Inset[
    Grid[{{Graphics[{Red, Disk[]}, ImageSize -> 10], 
       "z = -2"}, {Graphics[{Blue, Disk[]}, ImageSize -> 10], 
       "z = -1"}, {Graphics[{Green, Disk[]}, ImageSize -> 10], 
       "z = 1"}, {Graphics[{Orange, Disk[]}, ImageSize -> 10], 
       "z = 2"}}], {Right, Top}, {Right, Top}]},
 AxesOrigin -> {0, 0, 0}]
POSTED BY: Henrik Schachner
Posted 2 hours ago

You can simplify your plot quite a bit by using built in functions and options:

With[
 {segregatedData = GroupBy[U, Last]},
 ListPointPlot3D[segregatedData, PlotLegends -> Keys[segregatedData], 
  AxesLabel -> {"X", "Y", "Z"}, AxesOrigin -> {0, 0, 0}, 
  Boxed -> False, 
  PlotLabel -> Style["64 points colored by Z layer", Bold, 14]]]

enter image description here

You might want to add face grids or you might want to make the axes clearer with additional styling.

POSTED BY: Eric Rimbey

You can try the option AxesOrigin -> {0, 0, 0}. To add arrowheads to the axes, the option AxesStyle -> Arrowheads[0.05] works in 2D but not in 3D.

POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard