1

I am creating a plot with pgfplots and using symbolic (textual) input coordinates. My MWE is as follows:

\providecommand{\myrootdir}{..}
\documentclass[tikz]{standalone}
\onlyifstandalone{
    \usepackage{pgfplots}
    \pgfplotsset{compat=1.15}
}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        width=80mm,height=50mm,
        xtick=data,
        symbolic x coords={yellow, green, blue}]

        \addplot+[sharp plot]
        coordinates {(yellow, 2) (green, 1) (blue, 3)};
        \addplot+[sharp plot]
        coordinates {(yellow, 2.5) (green, 2) (blue, 3)};
        \addplot+[sharp plot]
        coordinates {(yellow, 3) (green, 3) (blue, 1)};

    \end{axis}
\end{tikzpicture}
\end{document}

This produces the following plot:

A plot with misaligned input coordinates

As you can see in the image, the input coordinate "green" is misaligned (too high). How can I fix this?

1

The input coordinate labels seem to get misaligned as the text is moved as close to the x axis as possible, disregarding the other labels.

As "green" does not contain any "high" letter, such as "l" in "yellow" and "b" or "l" in "blue", it can be moved closer to the axis.

To solve this, I used the workaround of capitalising all labels. Another possibility would be to reword the labels, if possible.

A plot with well-aligned input coordinates

I am looking forward to a better solution, but I posted this question to be able to show one option for solving it that I used in my document. I hope it is helpful to some!

| improve this answer | |
  • add text height=2ex to yticklabel style – percusse May 17 '18 at 15:57
  • Do you mean the xticklabel? Either way, neither seem to work. :/ – vauhochzett May 17 '18 at 16:00
  • xticklabel style={text height=3ex} works for me \ – percusse May 17 '18 at 16:02
  • 2
    I closed this question as a duplicate. Have a look there how to solve this "problem". – Stefan Pinnow May 17 '18 at 16:03
  • If the question and/or the answer(s) are useful, feel free to upvote there ... – Stefan Pinnow May 18 '18 at 20:05

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