6

I have a plot where the x-axis and y-axis coordinates at the origin are really close and kind of overlapping

Plot[x, {x, 2000, 5000}, 
  PlotRange -> {{2000, 5000}, {2000, 5000}}, LabelStyle -> {28, Black, Bold}]

what I have

I want to fix this by moving the x-axis labels down, like below. Is there an easy way to do this?

what I want

kglr
  • 394,356
  • 18
  • 477
  • 896
  • I would recommend simply not using overly large fonts. Can you explain why you need such huge fonts? In what context do you plan to use this figure? Website? Publication? Poster? If you let us know, perhaps I can show you a reasonable way to make the figure fit in. – Szabolcs May 10 '20 at 14:59
  • @HighPerformanceMark It took me a while to see the difference too. Look at the tick labels "2000". They overlap – Szabolcs May 10 '20 at 15:00
  • 1
    Oh, I see, it's one of those puzzles where you have to find 8 differences between two drawings of the 'same' picture. Hang on while I look for the rest :-) – High Performance Mark May 10 '20 at 15:04
  • @Szabolcs It's for a publication, but I also make the font large for posters. I found the only way to have the axes readable is to have a fairly large font. I don't know a nice way to avoid it, but please share if you do know one! – nullgeodesic May 10 '20 at 15:34
  • 1
    The workflow I use is mostly described in the documentation of my MaTeX package. If you install the package, it can be accessed at the addess MaTeX/tutorial/PreparingFiguresToSize (or just search the docs for MaTeX and there are link to this tutorial at the end of most reference pages). Sorry, I do not have this text in a format independent of the package. The main idea is to prepare figures to a known size. E.g., you decide you want it 8 cm wide (because you verified that this matches the page format that your target journal uses). – Szabolcs May 10 '20 at 16:11
  • Then you specify precisely 8 cm in the ImageSize, and export to PDF or EPS as such. It is important not include the figure at its native size in the document and not resize it afterwards. If we do this, we can set the fonts in the figure to match the main text of the document. 8 pt or 10 pt usually works well, just be consistent throughout your figures. Now the fact about how Mathematica draws tick labels and frame/axis labels is that it is not adjustable (at least not without ugly hacks), and it is optimized only for the typical font size range (around 10 pt). – Szabolcs May 10 '20 at 16:13
  • Should you deviate from the usual font size, the spacing just won't be right. I usually have the opposite problem than you because I typically use 8 pt, which is smaller than the default. Still, it works relatively well. 28 pt size is very different from the default, and just won't match. But I assume you don't want huge 28 pt sizes in your publication. That is both unnecessary and ugly. – Szabolcs May 10 '20 at 16:14
  • With that introduction, my recommendation is the following: generate the at their intended size for the publication. Then you can use reasonable font sizes (not 28 pt). For the publication, do not resize (no width in LaTeX). For the poster, rescale them proportionally. Is this complicated? Perhaps yes, but it worked well for me so far. Hopefully this is helpful to you. – Szabolcs May 10 '20 at 16:16
  • If you really really have to adjust the spacing, here's another hack than what @kglr described: https://mathematica.stackexchange.com/a/131384/12 Still, it's a hack, it's ugly, it's inconvenient, and does not come without compromises. – Szabolcs May 10 '20 at 16:16
  • I wrote "it is important not to include the figure at its native size". I meant to say "it is important to include the figure at its native size". – Szabolcs May 10 '20 at 16:19

2 Answers2

4

Add a tick with a sufficiently large length in the negative direction:

off = {0, .3};
ticks = Prepend[Charting`ScaledTicks["Linear"][2000, 5000, {10, 5}], 
  {2000., "", off, Red}];

Plot[x, {x, 2000, 5000}, PlotRange -> {{2000, 5000}, {2000, 5000}}, 
 LabelStyle -> {28, Black, Bold}, Ticks -> {ticks, Automatic}, 
 ImageSize -> Large]

enter image description here

Use off = {0, .03} and change Red to Opacity[0] to get

enter image description here

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

Here is a relative simple way to do it.

Plot[x, {x, 2000, 5000},
  PlotRange -> {{2000, 5000}, {2000, 5000}},
  LabelStyle -> {20, Black, Bold},
  Ticks -> 
    {{#, Column[{"", #}, Spacings -> 0]} & /@ Range[2000, 5000, 500], Automatic},
  ImageSize -> Large]

plot

Update

The following is added to address concerns raised by the OP in a comment to this answer.

To do what you ask for, you have to explicitly specify the length of the major and minor ticks and give the option ImageSize to Columnn. Like so:

Plot[x, {x, 2000, 5000},
  PlotRange -> {{2000, 5000}, {2000, 5000}},
  LabelStyle -> {20, Black, Bold},
  Ticks ->
    {If[Mod[#, 500] == 0,
       {#, Column[{#}, ItemSize -> {Automatic, 1.5}], {.0075, 0}},
       {#, "", {.005, .0}}] & /@ Range[2000, 5000, 100],
    Automatic},
  ImageSize -> Large]

plot

m_goldberg
  • 107,779
  • 16
  • 103
  • 257