# How to label axes in 3D plot adequately?

The following code produces plot with axes labels, which are jumping constantly.

object = Cuboid[{-100, -100, 300}, {100, 100, 500}];

screenWidth = 640;
screenHeight = 480;
screen = Polygon[{{-screenWidth/2, -screenHeight/2,
0}, {-screenWidth/2, screenHeight/2, 0}, {screenWidth/2,
screenHeight/2, 0}, {screenWidth/2, -screenWidth/2, 0}}];

spaceWidth = 2000;
spaceHeight = 2000;
spaceDepth = 2000;
Graphics3D[{Opacity[0.5], object}, Axes -> True,
AxesOrigin -> {0, 0, 0},
PlotRange -> {{-spaceWidth/2, spaceWidth/2}, {-spaceHeight/2,
spaceHeight/2}, {-spaceDepth/2, spaceDepth/2}},
AxesLabel -> {"X", "Y", "Z"}, BoxRatios -> {1, 1, 1}]


Sample 1

Cube is near Y label, although it is on Z axes.

Sample 2

Cube is now near X label, after rotated infinitesimally.

• relevant: stackoverflow.com/q/6182804/615464 – Sjoerd C. de Vries Jun 13 '13 at 20:35
• Inspired by cormullion: {Text[Style[#1, 25, Bold, Black], Scaled@#2] & @@@ {{"x", {.9, .5, .55}}, {"y", {.5, .9, .55}}, {"z", {.5, .55, .9}}}} – Kuba Jun 14 '13 at 10:28
• @kuba looks good, and simpler! (I'd upvote it... :) – cormullion Jun 14 '13 at 10:45
• @cormullion As You wish :) – Kuba Jun 14 '13 at 10:50

Inspired by cormullion I've made this:

Graphics3D[{
Text[Style[#1, 25, Bold, Black], Scaled@#2] & @@@
{{"x", {.9, .5, .55}}, {"y",   {.5, .9, .55}}, {"z", {.5, .55, .9}}}}
]


(please keep in mind that it is solution for range in form PlotRange->max, but can be easily customized).

And using my latest code:

• One upvote delivered as promised... :) – cormullion Jun 14 '13 at 11:07

I can't help you with the axes labels. I've never liked the way they move about, and to help me get my spatial orientation I use this short function that draws some labels in 3D space:

 axesLabels[loc_, scale_] := Module[
{x3 = Rescale[{{30, 90, 0}, {50, 65, 0}, {30, 40, 0}, {40, 40, 0},
{60, 60, 0}, {80, 40, 0}, {90, 40, 0}, {70, 65, 0},
{90, 90, 0}, {80, 90, 0}, {60, 70, 0}, {40, 90, 0}},
{0, 100}, {-.5, .5}],
y3 = Rescale[{{0, 30, 90}, {0, 55, 60}, {0, 35, 30}, {0, 50, 30},
{0, 90, 90}, {0, 75, 90}, {0, 62, 70}, {0, 45, 90},
{0, 30, 90}},
{0, 100}, {-.5, .5}],
z3 = Rescale[{{40, 0, 90}, {90, 0, 90}, {60, 0, 40}, {90, 0, 40},
{90, 0, 30}, {40, 0, 30}, {70, 0, 80}, {40, 0, 80},
{40, 0, 90}}, {0, 100}, {-.5, .5}]
},
{Scale[Translate[Polygon[x3], {loc, 0, 0}], scale],
Scale[Translate[Polygon[y3], {0, loc, 0}], scale],
Scale[Translate[Polygon[z3], {0, 0, loc}], scale]}]


Yes, I know it looks terrible, but it does the job for me. The first option is how far down the axis, the second is the scale.

Graphics3D[{
Opacity[0.5],
object,
Green,
Opacity[1],
axesLabels[800, 200]
},
Axes -> True ...


gives:

and they stay in the right place when you rotate the view...