10
$\begingroup$

On similar lines as Is there an option to change the space/distance between tick labels and axes labels for plots? but I would like to reduce the distance between the tick mark and the tick label that appears below it. For eg:

In this figure, I would like to reduce the distance between -2 in the x axis and the tick mark corresponding to it enter image description here

Edit:

Adding the code that generated this figure:

    cutoff = 0.52;
grp1 = {{-4.10855, 1}, {-3.18, 2}, {-2.97477, 3}, {-2.40408, 
    4}, {-2.19854, 5}, {-1.77951, 6}, {-1.76863, 7}, {-1.75573, 
    8}, {-1.71227, 9}, {-1.64262, 10}, {-1.48712, 11}, {-1.42243, 
    12}, {-1.29815, 13}, {-1.18774, 14}, {-1.03156, 15}, {-0.978796, 
    16}, {-0.971106, 17}, {-0.922292, 18}, {-0.862833, 
    19}, {-0.807821, 20}, {-0.775937, 21}, {-0.750941, 
    22}, {-0.737334, 23}, {-0.715059, 24}, {-0.712102, 
    25}, {-0.693181, 26}, {-0.69129, 27}, {-0.674491, 28}, {-0.644356,
     29}, {-0.620938, 30}, {-0.59347, 31}, {-0.589228, 
    32}, {-0.581852, 33}, {-0.580016, 34}, {-0.56826, 35}, {-0.566551,
     36}, {-0.561733, 37}, {-0.55583, 38}, {-0.551104, 
    39}, {-0.549835, 40}, {-0.535232, 41}, {-0.53486, 42}, {-0.533395,
     43}, {-0.523652, 44}, {-0.520547, 45}, {-0.508359, 
    46}, {-0.506626, 47}, {-0.491825, 48}, {-0.490019, 49}, {-0.477, 
    50}, {-0.473228, 51}, {-0.470723, 52}, {-0.470415, 
    53}, {-0.454857, 54}, {-0.454278, 55}, {-0.452099, 
    56}, {-0.421126, 57}, {-0.41768, 58}, {-0.415444, 59}, {-0.402139,
     60}, {-0.387403, 61}, {-0.380952, 62}, {-0.374082, 
    63}, {-0.373277, 64}, {-0.370055, 65}, {-0.364634, 
    66}, {-0.361553, 67}, {-0.361208, 68}, {-0.360869, 69}, {-0.34248,
     70}, {-0.340748, 71}, {-0.33172, 72}, {-0.330729, 
    73}, {-0.311965, 74}, {-0.310625, 75}, {-0.304104, 
    76}, {-0.302831, 77}, {-0.302533, 78}, {-0.29397, 79}, {-0.291521,
     80}, {-0.289982, 81}, {-0.27621, 82}, {-0.264455, 
    83}, {-0.256689, 84}, {-0.250929, 85}, {-0.246889, 
    86}, {-0.228836, 87}, {-0.22671, 88}, {-0.202538, 89}, {-0.196612,
     90}, {-0.187845, 91}, {-0.187817, 92}, {-0.179211, 
    93}, {-0.173247, 94}, {-0.165728, 95}, {-0.163806, 
    96}, {-0.153261, 97}, {-0.132747, 98}, {-0.122831, 
    99}, {-0.117507, 100}, {-0.113069, 101}, {-0.102309, 
    102}, {-0.0976552, 103}, {-0.0951561, 104}, {-0.0894875, 
    105}, {-0.0876338, 106}, {-0.087434, 107}, {-0.0845464, 
    108}, {-0.0757364, 109}, {-0.0635816, 110}, {-0.0621387, 
    111}, {-0.0580457, 112}, {-0.0558367, 113}, {-0.0529842, 
    114}, {-0.0478612, 115}, {-0.0444608, 116}, {-0.0410887, 
    117}, {-0.0398071, 118}, {-0.0322021, 119}, {-0.0200628, 
    120}, {-0.0182955, 121}, {-0.0144614, 122}, {-0.0138035, 
    123}, {-0.00716598, 124}, {0., 125}, {0.0103846, 126}, {0.0205011,
     127}, {0.0341349, 128}, {0.059813, 129}, {0.0954803, 
    130}, {0.123192, 131}, {0.123591, 132}, {0.147797, 
    133}, {0.166342, 134}, {0.16952, 135}, {0.186956, 136}, {0.206183,
     137}, {0.210853, 138}, {0.260639, 139}, {0.287231, 
    140}, {0.30835, 141}, {0.314636, 142}, {0.329798, 143}, {0.334356,
     144}, {0.36056, 145}, {0.383386, 146}, {0.45576, 147}, {0.457104,
     148}, {0.46041, 149}, {0.482364, 150}};

grp2 = {{0.559846, 151}, {0.603893, 152}, {0.692402, 153}, {0.736425, 
    154}, {0.742579, 155}, {0.750076, 156}, {0.879458, 
    157}, {0.967285, 158}, {0.988934, 159}, {1.04353, 160}, {1.06206, 
    161}, {1.12605, 162}, {1.13691, 163}, {1.14313, 164}, {1.22551, 
    165}, {1.24425, 166}, {1.32567, 167}, {1.35547, 168}, {1.3873, 
    169}, {1.46251, 170}, {1.48027, 171}, {1.48587, 172}, {1.50248, 
    173}, {1.50557, 174}, {1.52349, 175}, {1.52676, 176}, {1.61266, 
    177}, {1.6306, 178}, {1.71358, 179}, {1.73984, 180}, {1.79301, 
    181}, {1.81201, 182}, {1.86031, 183}, {1.90378, 184}, {1.91104, 
    185}, {1.932, 186}, {1.94978, 187}, {1.96444, 188}, {1.97321, 
    189}, {1.98785, 190}, {1.99161, 191}, {2.02637, 192}, {2.04347, 
    193}, {2.05299, 194}, {2.07511, 195}, {2.08866, 196}, {2.17186, 
    197}, {2.19635, 198}, {2.2132, 199}, {2.22343, 200}, {2.22452, 
    201}, {2.24434, 202}, {2.25782, 203}, {2.2627, 204}, {2.27745, 
    205}, {2.46167, 206}, {2.48096, 207}, {2.54055, 208}, {2.64996, 
    209}, {2.65934, 210}, {2.73535, 211}, {2.78724, 212}, {2.79484, 
    213}, {2.79819, 214}, {2.88538, 215}, {2.89362, 216}, {2.96651, 
    217}, {3.00729, 218}, {3.07063, 219}, {3.11961, 220}, {3.19508, 
    221}, {3.2295, 222}, {3.23329, 223}, {3.27631, 224}, {3.3876, 
    225}, {3.41121, 226}, {3.46174, 227}, {3.61129, 228}, {3.61579, 
    229}, {3.64525, 230}, {3.77605, 231}, {3.91162, 232}, {3.91579, 
    233}, {3.9266, 234}, {4.12641, 235}, {4.15509, 236}, {4.21151, 
    237}, {4.25269, 238}, {4.41959, 239}, {4.4295, 240}, {4.45912, 
    241}, {4.70492, 242}, {4.72227, 243}, {4.93772, 244}, {5.7519, 
    245}, {5.92314, 246}, {6.20269, 247}, {6.23834, 248}, {7.70686, 
    249}};

Show[ListPlot[{grp1, grp2}, Frame -> True, 
  FrameLabel -> {Column[{Style["x", FontFamily -> "Courier"], 
      Style["y", FontFamily -> "Courier"]}, Center], "(b) z", None, 
    None, None}, AspectRatio -> 1.8, 
  PlotStyle -> {{Blue, PointSize[0.01]}, {Red, PointSize[0.01]}}, 
  FrameTicks -> {{{-2, -2, {0, 0.03}}, {0, 0, {0, 0.03}}, {cutoff, 
      "   " <> ToString[N[Round[cutoff, 10^-1]]], {0, 0.03}}, {2, 
      2, {0, 0.03}}, {4, 4, {0, 0.03}}, {6, 6, {0, 0.03}}}, {{1, 
      1, {0, 0.03}}, {50, 50, {0, 0.03}}, {100, 100, {0, 0.03}}, {150,
       150, {0, 0.03}}, {200, 200, {0, 0.03}}}, None, None}, 
  AxesOrigin -> {1, 0}, Axes -> False, ImageSize -> {211, 335}, 
  ImagePadding -> {{50, 0}, {50, 0}}, 
  PlotRange -> {{Automatic, Automatic}, {1, 250}}], 
 Graphics[{Dashed, Black, Line[{{cutoff, 1}, {cutoff, 249}}]}]]
$\endgroup$
1
  • 1
    $\begingroup$ The gap seems much bigger than default so we really need the code that generated that plot to give the best answer $\endgroup$ Jul 30, 2013 at 22:52

2 Answers 2

5
$\begingroup$

Assuming the ticks are FrameTicks, I'll generate an example plot with a frame and then replace its ticks using Framed with negative FrameMargins in the vertical directions:

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

With[{verticalShrink = 5},
 Show[p, FrameTicks -> (Map[# /. ({x_, xL_, dir___} :> {x, 
          Framed[xL, FrameStyle -> None, 
           FrameMargins -> {{Automatic, 
              Automatic}, {-1, -1} verticalShrink}], dir}) &, 
     FrameTicks /. First[AbsoluteOptions[p, FrameTicks]], {2}])]
 ]

frame

Or with the frame labels similar to your example:

p = Plot[Sin[x], {x, 0, 10}, Frame -> True, FrameLabel -> {"\*GridBox[{
{x},
{y}
}]", "\!\(\*FormBox[\(b(z)\),
TraditionalForm]\)"}];

With[{verticalShrink = 5},
 Show[p, FrameTicks -> (Map[# /. ({x_, xL_, dir___} :> {x, 
          Framed[xL, FrameStyle -> None, 
           FrameMargins -> {{Automatic, 
              Automatic}, {-1, -1} verticalShrink}], dir}) &, 
     FrameTicks /. First[AbsoluteOptions[p, FrameTicks]], {2}])]
 ]

frame2

Since you didn't provide the code that produced your example, I can only add that the specific tick style (pointing outward) can be created the usual way in the plot p, and then you use the With block on the desired plot p.

I used a quick-and dirty shrinking trick here: indiscriminately make the vertical frame margins negative in both top and bottom directions, so that I don't have to treat the vertical and horizontal ticks separately (the vertical alignment of the vertical ticks labels stays centered). But this (crude) top/bottom balanced approach means the shrinkage of vertical spacing is limited, and you can't make the tick labels touch the axis.

If you want to have more control, you'll need to make the replacement of tick labels by Framed tick labels act only on the horizontal bottom labels. The FrameMargins at top and bottom then should be chosen unequal. I can add that if it's necessary. See also this answer.

$\endgroup$
1
  • $\begingroup$ That helps. I did play around with the frame margin etc to get what I want. I was wondering if there is any way to determine what is the space left outside of the frame margin by default. When combining plots, despite adjusting imagesize, imagepadding etc, the difference in the distance between tick labels and tick marks were unequal in my figure. Anyways, for now, I decreased the distance of frame margin in one and increased in the other to make them equal. $\endgroup$
    – preeti
    Jul 30, 2013 at 22:05
0
$\begingroup$

For me, the labels seem to stay close to the ticks, whatever length you give them:

Manipulate[
 ListLinePlot[Sort@RandomReal[300, {50}], Frame -> True, 
  FrameTicks -> 
   {
    Table[{x, ToString[x], {0, n}}, {x, 0, 50, 5}],
    Table[{x, ToString[x], {0, n}}, {x, 0, 300, 25}]
    }
  ], 
 {n, -0.02, 0.02, 0.005}]

ticks

$\endgroup$

Your Answer

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

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