2
$\begingroup$

How can I modify the code below to add some padding between my tick marks and 3D plot? It is not a problem in this example, but often my tick marks collide with my axes.

r = Norm[{x, y}];
Plot3D[r^2, {x, -Pi, Pi}, {y, -Pi, Pi}, TicksStyle -> Large]

Apologies if trivial question.

$\endgroup$
2
  • $\begingroup$ You could wrap each tick label in Framed and use FrameMargins but seems like a kluge. $\endgroup$
    – rivercfd
    Oct 29, 2014 at 13:43
  • $\begingroup$ This quesiton appears to be a duplicate so I have marked it as such. Please read the question linked at the top of your post as well as its answers. If you feel that your question is not the same please edit it to clarify in what way it is different. If the question is the same but the answers are unsatisfactory please explain that as well. $\endgroup$
    – Mr.Wizard
    Oct 30, 2014 at 0:01

2 Answers 2

0
$\begingroup$

Try this:

 r = Norm[{x, y}];
Plot3D[r^2, {x, -Pi, Pi}, {y, -Pi, Pi}, 
 Ticks -> {{{-2, " -2 "}, {0, " 0 "}, {2, " 2 "}}, {{-2, " -2 "}, {0, 
     " 0 "}, {2, " 2 "}}, {{0, "0 "}, {10, "10 "}, {20, "20 "}}}, 
 TicksStyle -> Large]

giving this: enter image description here

Have fun!

Then try this:

     r = Norm[{x, y}];
sp = Spacer[20];
lst = {{{-2, "-2"}, {0, "0"}, {2, "2"}}, {{-2, "-2"}, {0, "0"}, {2, 
     "2"}}, {{0, "0"}, {10, "10"}, {20, "20"}}};

Plot3D[r^2, {x, -Pi, Pi}, {y, -Pi, Pi}, 
 Ticks -> Map[ReplaceAll[#, {x_, y_} -> {x, Row[{sp, y, sp}]}] &, 
   lst], TicksStyle -> Large]

and play with the argument of the Spacer. enter image description here

$\endgroup$
1
  • $\begingroup$ Unfortunately this doesn't solve my problem. I want to specify how much padding there is. Thanks though :) $\endgroup$
    – Tom
    Oct 29, 2014 at 14:22
0
$\begingroup$

You can wrap the tick labels with Pane and adjust the distances from the axes using the FrameMargins settings.

ClearAll[lF];
lF[l_:0, r_:0, t_:0, b_:0] := Pane[Style[#, FontSize->Large], 
   FrameMargins->{{l, r}, {t, b}}] &;

r = Norm[{x, y}];

Row[{Plot3D[r^2, {x, -Pi, Pi}, {y, -Pi, Pi}, ImageSize -> 500,TicksStyle -> Large,
    Ticks -> {{#, #} & /@ {-2, 0, 2}, {#, #} & /@ {-2, 0, 2},
              {#, lF[0, 20, 0, 0]@#} & /@ Range[0, 20, 5]}],
    Plot3D[r^2, {x, -Pi, Pi}, {y, -Pi, Pi}, ImageSize -> 500,TicksStyle -> Large,
      Ticks -> {{#, #} & /@ {-2, 0, 2}, {#, lF[20, 0]@#} & /@ {-2, 0, 2},
               {#, lF[0, 50, 0, 0]@#} & /@ Range[0, 20, 5]}]}, Spacer[5]]

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.