13
$\begingroup$

I'm looking for a way to have the axes at the origin in a 3D plot and to label the (x,y,z) axes in the usual way---with x near the end of the drawn portion of the x axis, y near the end of the drawn portion of the y axis, etc. I've tried

Plot3D[x^2 + y^2 + 3, {x, -3, 3}, {y, -3, 3}, 
      AxesOrigin -> {0, 0, 0}, PlotRange -> {-1, 20}, AxesLabel -> {x, y, z}]

which works well for the axes position but horribly for the labeling. (The labels appear all together near the origin; it is not at all clear which axis is associated with which label.) Any suggestions?

$\endgroup$
  • $\begingroup$ In Mathematica 11, the labels position themselves automatically at the ends of the axis when AxesOrigin is specified. (Although, the labels are not always at the positive ends of the axes.) $\endgroup$ – Chris Chudzicki Feb 6 '18 at 14:23
11
$\begingroup$

With Scaled position:

Show[{Plot3D[x^2 + y^2 + 3, {x, -3, 3}, {y, -3, 3}, 
      AxesOrigin -> {0, 0, 0}, PlotRange -> {-1, 20}], 
  Graphics3D[{Text["x", Scaled[{-.05, .5, 0}], {0, -1}], 
    Text["y", Scaled[{.5, -.05, 0}], {0, -1}], 
    Text["z", Scaled[{.5, .5, 1.1}]]}]}, Boxed -> False]
$\endgroup$
9
$\begingroup$

You can add them manually:

Show[{Plot3D[x^2 + y^2 + 3, {x, -3, 3}, {y, -3, 3}, 
 AxesOrigin -> {0, 0, 0}, PlotRange-> {-1, 20}], 
 Graphics3D[{Text["x", {3, 0, 0}], Text["y", {0, 3, 0}], Text["z", {0, 0, 20}]}]}]

Mess around with the Text[ ] functions to change sizes and positions. I'm sure there must be a better way, though.

$\endgroup$
  • 1
    $\begingroup$ using Scaled location can help to place labels: Show[{Plot3D[x^2 + y^2 + 3, {x, -3, 3}, {y, -3, 3}, AxesOrigin -> {0, 0, 0}, PlotRange -> {-1, 20}], Graphics3D[{Text["x", Scaled[{-.1, .5, 0}]], Text["y", Scaled[{.5, -.1, 0}]], Text["z", Scaled[{.5, .5, 1.1}]]}]}] $\endgroup$ – halmir Mar 18 '13 at 18:41
  • $\begingroup$ That's a good and scalable (pun not intended) solution. I knew there must be improvements. $\endgroup$ – nickjamesuk Mar 18 '13 at 18:48
  • $\begingroup$ @halmir, please feel free to post that as an answer, too. $\endgroup$ – Verbeia Mar 18 '13 at 20:28

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.