1

I found this beautiful example:

\begin{tikzpicture}
  \begin{axis}[title  = Contributions per category at LaTeX-Community.org,
    xbar,
    y axis line style = { opacity = 0 },
    axis x line       = none,
    tickwidth         = 0pt,
    enlarge y limits  = 0.2,
    enlarge x limits  = 0.02,
    symbolic y coords = {LaTeX, Tools, Distributions, Editors},
    nodes near coords,
  ]
  \addplot coordinates { (57727,LaTeX) (5672,Tools) (2193,Distributions) (11106,Editors) };
  \addplot coordinates { (14320,LaTeX) (1615,Tools) (560,Distributions) (3075,Editors)  };
  \legend{Topics, Posts}
  \end{axis}
\end{tikzpicture}

It gives a nice bar chart:

nice bar chart

But the example is incredibly misleading! See what happens when I try to remove the 'editors' category:

\begin{tikzpicture}
  \begin{axis}[title  = Contributions per category at LaTeX-Community.org,
    xbar,
    y axis line style = { opacity = 0 },
    axis x line       = none,
    tickwidth         = 0pt,
    enlarge y limits  = 0.2,
    enlarge x limits  = 0.02,
    symbolic y coords = {LaTeX, Tools, Distributions},
    nodes near coords,
  ]
  \addplot coordinates { (57727,LaTeX) (5672,Tools) (2193,Distributions) };
  \addplot coordinates { (14320,LaTeX) (1615,Tools) (560,Distributions) };
  \legend{Topics, Posts}
  \end{axis}
\end{tikzpicture}

oops

Clearly something is missing and/or going wrong. How do I properly add or remove categories from this bar chart? Why did it work in the example?

3

It appears that the example was missing a ytick = data argument, which ensures that there are exactly as many labels as categories.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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