1
$\begingroup$

I have a little problem that's driving me crazy. The problem will be clear from the graphic: the text of the tick labels. on the Y-Axis are crossing/overlaying.

I tried everything but I found nothing that could fix this problem. Texts of the Ticks overlay

For anyone interested, here's the code:

 Plot[{1/(5*x)}, {x, 1.8, 6}, GridLines -> {{{4, Red}, {3.5, Red}}, None}, AxesLabel -> {L, W/P}, Ticks -> {None, {{0.049, W/Subscript[P, 2]}, {0.057, W/Subscript[P, 1]}}}, TicksStyle -> Tiny, PlotRange -> {0.02, 0.12}, AxesOrigin -> {1, 0.02}, AxesStyle -> Arrowheads[0.04]] 

I would be really really glad if someone had a solution for this!

$\endgroup$
4
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$ Commented Apr 21, 2015 at 23:03
  • 1
    $\begingroup$ The ticks are close enough in location that you'll either need to tinker with imagesize, aspect ratio, or use a string for the tick ("W/...") using the editing functions to subscript - that will give to much more vertical room. $\endgroup$ Commented Apr 21, 2015 at 23:13
  • $\begingroup$ try Ticks -> {None, {{0.049, Style[Row[{"W / ", Subscript[P, 2]}], 14]}, {0.057, Style[Row[{"W / ", Subscript[P, 1]}], 15]}}}? $\endgroup$ Commented Apr 22, 2015 at 0:16
  • $\begingroup$ Thank you very much. I tried to find a way to make the fraction smaller, but there seems no way in Mathematica. I did it your way now. $\endgroup$ Commented Apr 22, 2015 at 1:29

2 Answers 2

3
$\begingroup$

Wrapping your tick labels in DisplayForm[AdjustmentBox[...]]) and setting the BoxBaselineShift option will move the labels vertically so they don't clash. Positive numbers for this option move the content down; negative numbers move it up. According to the documentation, the units are x-heights, but for this example, I found I needed numbers larger than 1. This was a bit surprising but might be because Mathematica is taking the x-height from the smaller font size of the fraction, not from normal text.

Plot[{1/(5*x)}, {x, 1.8, 6}, GridLines -> {{{4, Red}, {3.5, Red}}, None}, AxesLabel -> {L, W/P}, Ticks -> {None, {{0.049, DisplayForm@ AdjustmentBox[W/Subscript[P, 2], BoxBaselineShift -> 9]}, {0.057, DisplayForm@ AdjustmentBox[W/Subscript[P, 1], BoxBaselineShift -> -6]}}}, TicksStyle -> Tiny, PlotRange -> {0.02, 0.12}, AxesOrigin -> {1, 0.02}, AxesStyle -> Arrowheads[0.04]] 

enter image description here

$\endgroup$
3
$\begingroup$

Re-using the trick from this answer

Plot[{1/(5*x)}, {x, 1.8, 6}, GridLines -> {{{4, Red}, {3.5, Red}}, None}, AxesLabel -> {L, W/P}, Ticks -> {None, {{0.049, Style[Pane[Style[W/Subscript[P, 2], 16], BaselinePosition -> (Bottom -> Top), FrameMargins -> {{0, 0}, {60, 0}}, ImageMargins -> {{0, 0}, {-60, 0}}]]}, {0.057, Style[Pane[Style[W/Subscript[P, 1], 16], BaselinePosition -> (Top -> Bottom), FrameMargins -> {{0, 0}, {0, 60}}, ImageMargins -> {{0, 0}, {0, -60}}]]}}}, TicksStyle -> Tiny, PlotRange -> {0.02, 0.12}, AxesOrigin -> {1, 0.02}, AxesStyle -> Arrowheads[0.04], ImageSize -> 500] 

enter image description here

Or

Plot[{1/(5*x)}, {x, 1.8, 6}, GridLines -> {{{4, Red}, {3.5, Red}}, None}, AxesLabel -> {L, W/P}, Ticks -> {None, {{0.049, Style[Row[{"W / ", Subscript[P, 2]}], 14]}, {0.057, Style[Row[{"W / ", Subscript[P, 1]}], 15]}}}, TicksStyle -> Tiny, PlotRange -> {0.02, 0.12}, AxesOrigin -> {1, 0.02}, AxesStyle -> Arrowheads[0.04], ImageSize -> 500] 

enter image description here

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.