0

I have a bar plot drawn with pgfplot and reading values from a CSV file. Is there a way to add a number above each bar where the number comes from another column in my CSV file ?

Manuel Selva
  • 1,839

1 Answers1

2

Sure there is, you can use \addplot[point meta=explicit] (or explicit symbolic for non numeric meta data) and give the table [meta=<column name>]. For the nodes to show up in your plot, give the axis nodes near coords option.

I stole some code from the manual to make a MWE:

\documentclass{article}
\usepackage{filecontents,pgfplots}
\pgfplotsset{compat=1.12}
\begin{filecontents*}{table.csv}
x, y, type
0, 0.8, a
1, 0.50235, b
2, 0.86873, c
3, 0.99997, d
4, 0.04889, e
5, 0.54402, f
\end{filecontents*}

\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar,
             nodes near coords,
             nodes near coords align={vertical},
             ]
\addplot[point meta=explicit symbolic] table [x=x, y=y, meta=type, col sep=comma] {table.csv};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here