5
$\begingroup$

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

$\endgroup$

2 Answers 2

9
$\begingroup$

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[..].

$\endgroup$
1
$\begingroup$

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!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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