# Plotting data lines properly annotated with pgfplots

I am plotting a series of rather busy plots consisting of many (5..25) lines of experimental data using pgfplots 1.14 and TikZ 3.0.1a. These curves are often overlapping, coexist near x or y axis, and generally have non-uniform appearance. I want to annotate each curve once, so currently the following piece of code for nodes is used:

\RequirePackage[l2tabu,orthodox]{nag}
\documentclass[12pt,a4paper]{report}

\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguage{german}

\usepackage{fontspec}

\usepackage{tikz}
\usetikzlibrary{
decorations.markings}
\tikzset{>=latex}

\usepackage{tikz-cd}

\usepackage{pgfplots}

\usepackage{chemfig}

\usepackage{chemmacros}

\begin{document}

\begin{tikzpicture}
\begin{axis} [
xlabel     = {pH},
ylabel     = {\ch{V^V}, \%},
axis lines = left,
clip       = false,
xmin = 0.5, xmax = 14,
ymin = 0,   ymax = 105,
xtick      = {1,2,...,13},
ytick      = {0,10,...,100},
width      = \textwidth,
height     = 12cm,
grid       = major,
grid style = {dashed,gray!30},
]

\addplot [smooth,thick] table [x = pH, y = {[VO2]+}, col sep = comma] {plots/distr-V-O-01.csv}
node[pos = 0.2, pin = {90:\ch{[VO2]^+}}, inner sep = 0pt]{};

\addplot [smooth,thick] table [x = pH, y = {[H3V10O28]3-}, col sep = comma] {plots/distr-V-O-01.csv}
node[pos = 0.5, pin = {-90:\ch{[H3V10O28]^{3-}}}, inner sep = 0pt]{};

\addplot [smooth,thick] table [x = pH, y = {[H2V10O28]4-}, col sep = comma] {plots/distr-V-O-01.csv}
node[pos = 0.7, pin = {120:\ch{[H2V10O28]^{4-}}}, inner sep = 0pt]{};

%%% And so on for each data series, there are about 25 entries on average

\end{axis}
\end{tikzpicture}

\end{document}


where \ch{A3B5O_x} is one of the chemical formulas corresponding to the data series. Figuring out the correct angle and node position every time (so that labels, lines and axis are not overlapping) is extremely tedious, and to me it seems there must be an easier way of labeling such data plots automatically, so that 3 parameters - pin length, pin angle and node position on the line - are correctly estimated automatically based on how occupied certain plot area is.

And yes, I really need pins, using nodes near coords or summarizing all data lines in a legend area clutter plots inevitably.

If you could suggest another tool for this job beyond pgfplots, which is XeLaTeX-friendly, please feel free to do so.

I'm not sure how to attach .csv file properly, so here are the first lines from data file:

pH,[VO2]+,[H3V10O28]3-,[H2V10O28]4-,[HV10O28]5-,[V10O28]6-,[V4O12]4-,[H2VO4]-,[H2V2O7]2-,[V6O18]6-,[V5O15]5-,[V3O10]5-,[V4O13]6-,[HV4O13]5-,[HV2O7]3-,[HVO4]2-,[V2O7]4-,[VO4]3-
1,,0.021,,,,,,,,,,,,,,,
1,,,0.122,,,,,,,,,,,,,,
1.0099,99.62,,,,,,,,,,,,,,,,
1.0929,93.542,,,,,,,,,,,,,,,,
1.1033,,,3.605,,,,,,,,,,,,,,
1.1295,,3.035,,,,,,,,,,,,,,,
1.1328,90.377,,,,,,,,,,,,,,,,
1.1677,,,6.389,,,,,,,,,,,,,,
1.1991,86.072,,,,,,,,,,,,,,,,
1.2,,,,0.027,,,,,,,,,,,,,
1.252,82.906,,,,,,,,,,,,,,,,
1.271,,,9.994,,,,,,,,,,,,,,
1.2755,80.311,,,,,,,,,,,,,,,,
1.3187,77.082,,,,,,,,,,,,,,,,
1.3353,,,13.157,,,,,,,,,,,,,,
1.3558,,9.676,,,,,,,,,,,,,,,
1.3586,73.916,,,,,,,,,,,,,,,,
1.3739,,,15.309,,,,,,,,,,,,,,
1.3985,70.751,,,,,,,,,,,,,,,,


• One very minor unrelated comment: pgfplots is a separate package from pgf/TikZ, although it builds on that. It is TikZ that has 3.0.1a as the latest stable version, pgfplots has 1.14. – Torbjørn T. Feb 26 '17 at 9:25