16

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?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Chris Chudzicki
  • 335
  • 1
  • 2
  • 7
  • 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.) – Chris Chudzicki Feb 06 '18 at 14:23

2 Answers2

13

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]
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
halmir
  • 15,082
  • 37
  • 53
11

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.

kglr
  • 394,356
  • 18
  • 477
  • 896
nickjamesuk
  • 883
  • 6
  • 13
  • 1
    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}]]}]}] – halmir Mar 18 '13 at 18:41
  • That's a good and scalable (pun not intended) solution. I knew there must be improvements. – nickjamesuk Mar 18 '13 at 18:48
  • @halmir, please feel free to post that as an answer, too. – Verbeia Mar 18 '13 at 20:28