21

Is there any way to tell Mathematica 7 to use "traditional" axes rather than boxing a three-dimensional graph? That is, rather than the default view produced by

Plot3D[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},Boxed->False], alt text

I would like three "axis arrows" to emanate from the origin.

JRG
  • 804

2 Answers2

12

In the end, I ended up writing my own arrow routine, which produces scalable arrowheads and scalable labels:

axes[x_, y_, z_, f_, a_] := Graphics3D[ Join[{Arrowheads[a]}, Arrow[{{0, 0, 0}, #}] & /@ {{x, 0, 0}, {0, y, 0}, {0, 0, z}}, { Text[Style["x", FontSize -> Scaled[f]], {0.9*x, 0.1*y, 0.1*z}], Text[Style["y", FontSize -> Scaled[f]], {0.1 x, 0.9*y, 0.1*z}], Text[Style["z", FontSize -> Scaled[f]], {0.1*x, 0.1*y, 0.9*z}]}]]

The arguments are the x, y, and z positions of the x, y, and z arrows, respectively, f is the font scale (try about 0.05), and a is the arrowhead scale (about 0.05 should do it). This is combined with ordinary 3D graphics using Show[], as in

Show[Plot3D[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2}, Boxed -> False, PlotStyle -> Opacity[0.7], Mesh -> 4, Axes -> None], axes[2.5, 2.5, 1.5, 0.05, 0.02], PlotRange -> {{-3, 3}, {-3, 3}, {0, 1.5}}]

The resulting plot is

alt text

JRG
  • 804
8

You need the AxesOrigin Option.

Plot3D[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},Boxed->False, 
 AxesOrigin->{0,0,0}]

I misinterpreted your question in an earlier answer and I was suggesting using the AxesEdge Option which changes the sides of the bounding box on which the axes are displayed. However, you might still find that useful:

Plot3D[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2}, Boxed -> False, 
AxesEdge -> {{-1, -1}, {-1, -1}, {-1, -1}}]
Henry B.
  • 2,058
  • That's 50% of what I'm looking for - do you know if it's possible to cut off the negative bits, so that the axes are rays instead of lines? – JRG Jan 05 '11 at 23:02
  • @Josh Guffin: Do you need numbers on the axes? – Henry B. Jan 05 '11 at 23:22
  • In general no, but I would like them to be drawn by the system rather than adding them in by hand (with Graphics[] directives); I don't want to have to specify the length of the arrows every time. – JRG Jan 05 '11 at 23:25
  • @Josh Guffin: Yes. You read my mind. I think you can use the Scaled command to fix the size of relative size of the arrows. – Henry B. Jan 05 '11 at 23:51
  • "Traditional axes" to me sounds like the way mathematicians would typically sketch a 3D plot, no just with axes emanating from the origin, but with arrows at their positive ends and axis labels, too. – murray May 01 '15 at 01:07