6

A similar question has been axed before in the context of a Framed plot: see here. My plot is unframed so I wasn't able to apply the answer to the other question.

I create a histogram with the code below. The tick labels end up too tight to the axes themselves. How to make them be further way from the axes?

hg = Histogram[{10, 10, 20, 20, 20, 20, 20, 20, 30, 30, 30, 30, 30, 
30, 30, 30, 30, 30, 30, 30, 40, 40, 40, 40, 40, 50, 50, 50, 60, 
60}, {0, 60, 10}, "Count",
   PlotRange -> {{5, 65}, Automatic},
   BaseStyle -> Directive[FontFamily -> "cmr12", FontSize -> 100],
   Ticks -> {Range[0, 80, 10], Automatic},
   TicksStyle -> Directive["Label", 100, FontFamily -> "cmr12"],
   Axes -> {True, True},
   GridLines -> {None, Automatic},
   GridLinesStyle -> Black,
   ChartStyle ->  Directive[LightGray, EdgeForm[AbsoluteThickness[4]]],
   AspectRatio -> .4,
   ImageSize -> {3000, 1080}];
Magnify[hg, .25]

enter image description here

Wynne
  • 1,526
  • 9
  • 14

2 Answers2

9

You can use Framed on the tick labels and control the margins around the labels with the option FrameMargins:

Ticks -> {{#, Framed[#, FrameMargins -> 1, FrameStyle -> None]} & /@ Range[0, 80, 10], 
  {#, Framed[#, FrameMargins -> 1, FrameStyle -> None]} & /@ Range[0, 12, 2]}

enter image description here

You can set different margins for the four sides of the label:

Ticks -> {{#, Framed[#, FrameMargins -> {{0, 0}, {0, Scaled[.05]}}, 
      FrameStyle -> None]} & /@ Range[0, 80, 10], 
    {#, Framed[#, FrameMargins -> {{0, Scaled[.05]}, {0, 0}}, 
      FrameStyle -> None]} & /@ Range[0, 12, 2]}

enter image description here

Alternatively, you can use Pane[#, FrameMargins -> {{0, 0}, {0, Scaled[.05]}}] instead of Framed[..].

kglr
  • 394,356
  • 18
  • 477
  • 896
1

Try also this:

Manipulate[
 lab1 = Join[{{0, 0, n, Directive[White]}}, Range[10, 80, 10]];
 lab2 = Transpose[{Range[0, 12, 2], 
    Row[{#, Spacer[m]}] & /@ ToString /@ Range[0, 12, 2]}];
 hg = Histogram[{10, 10, 20, 20, 20, 20, 20, 20, 30, 30, 30, 30, 30, 
    30, 30, 30, 30, 30, 30, 30, 40, 40, 40, 40, 40, 50, 50, 50, 60, 
    60}, {0, 60, 10}, "Count", PlotRange -> {{5, 65}, Automatic}, 
   BaseStyle -> Directive[FontFamily -> "cmr12", FontSize -> 100], 
   Ticks -> {lab1, lab2}, 
   TicksStyle -> Directive["Label", 100, FontFamily -> "cmr12"], 
   Axes -> {True, True}, GridLines -> {None, Automatic}, 
   GridLinesStyle -> Black, 
   ChartStyle -> Directive[LightGray, EdgeForm[AbsoluteThickness[4]]],
    AspectRatio -> .4, ImageSize -> {3000, 1080}];
 Magnify[hg, .25], {n, 0.01, 0.3}, {m, 10, 30}]

enter image description here

and play with the sliders to position the ticks labels where you need them.

Have fun!

Alexei Boulbitch
  • 39,397
  • 2
  • 47
  • 96