I have two problems when trying to add the value of a data point above the data point. I am trying to solve this with a for-loop:
\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\def \myvalues{{50,50,31,25,24,24,24,24,24,24,24,24,24,24,24}}%
\begin{axis}[
width=\textwidth,
height=.40\textwidth,
xlabel={x},
ylabel={y},
xtick={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
ytick={20,25,30,35,40,45,50},
xmajorgrids,
ymajorgrids,
]
\addplot [black, mark=*, mark options={solid}]
table {%
1 50
2 50
3 31
4 25
5 24
6 24
7 24
8 24
9 24
10 24
11 24
12 24
13 24
14 24
15 24
};
\pgfplotsinvokeforeach{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}{
\pgfmathparse{\myvalues[#1-1]};
\node at (#1,\pgfmathresult+2){\pgfmathresult};
}
\end{axis}
\end{tikzpicture}
\end{document}
Problems:
- Document compiles without errors, but the nodes don't show up in the plot.
- How can I add an if-statement into the for-loop? For example to change the color of the node to red for the nodes 4 and 12?
Thanks a lot! -
nodes near coords. Addnodes near coordsright afterymajorgrids,in theaxisoptions and the first point is taken care of. – Torbjørn T. Mar 02 '17 at 12:15