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 ?
Asked
Active
Viewed 609 times
0
1 Answers
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}
Guilherme Zanotelli
- 7,787

\documentclassand ending with\end{document}) that we can compile and that illustrates your question. – gernot Nov 15 '16 at 11:02