13

Is there a way to force Plot and related functions to place the tick labels inside, rather than outside a frame? For example, consider,

Plot[Sin[x], {x, 0, 10}, Frame -> True]

When this line is executed, the tick labels are outside the bottom and left edges of the frame:

enter image description here

Is there an easy way to move them to the inside?

(Why place tick labels inside the frame, you ask? I would like to export plots to PDF in a specified absolute size, so that one major tick on the plot is exactly 1 cm on the printout. If the labels were not placed on the outside, padding the image, this could be easily done using ImageSize, as described here.)

Ted Pudlik
  • 345
  • 2
  • 6

2 Answers2

10

You could do something like this:

Plot[Sin[x], {x, 0, 10}, Frame -> True,
 Epilog -> {Table[Text[i, {i, -1}, {0, -1}], {i, Range[0, 10, 2]}],
  Table[Text[NumberForm[i, {2, 1}], {0, i}, {-1, 0}], {i, Range[-1, 1, .5]}]},
 FrameTicksStyle -> (FontOpacity -> 0),
 ImagePadding -> {{1, 1}, {1, 1}}]

Mathematica graphics

Heike
  • 35,858
  • 3
  • 108
  • 157
4

I don't know of an easy way, but with the help of Epilog, Inset and Scaled (the latter using a combo of absolute coordinates and scaled offsets) it's quite doable:

Plot[Sin[x], {x, 0, 10}, Frame -> True, 
 FrameTicks -> {{None, {{-1, ""}, {0, ""}, {1, ""}}}, {{{0, ""}, {Pi, 
      ""}, {2 Pi, ""}, {3 Pi, ""}}, None}}, 
  Epilog ->
  {
   Inset[0, Scaled[{0, -0.45}, {0, 0}]],
   Inset[\[Pi], Scaled[{0, -0.45}, {\[Pi], 0}]],
   Inset[2 \[Pi], Scaled[{0, -0.45}, {2 \[Pi], 0}]],
   Inset[3 \[Pi], Scaled[{0, -0.45}, {3 \[Pi], 0}]],
   Inset[-1, Scaled[{0.95, 0}, {0, -0.99}]],
   Inset[0, Scaled[{0.95, 0}, {0, 0}]],
   Inset[1, Scaled[{0.95, 0}, {0, 0.99}]]
   },
 BaseStyle -> {FontFamily -> "Arial", FontSize -> 14}
]

Mathematica graphics

Sjoerd C. de Vries
  • 65,815
  • 14
  • 188
  • 323