3

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,,,,,,,,,,,,,,,,

There are about 1000 lines. Here is a cropped area of the approximate plot

  • Welcome to TeX.SX! A minimal example of code seems necessary to better understand the problem. – egreg Feb 13 '17 at 22:18
  • 1
    As far as I know there is no automated way to do it which takes care of that the label isn't overlapping something else. – Stefan Pinnow Feb 13 '17 at 23:28
  • 1
    But if you have 25 lines, all of them showing in the same style which overlap multiple times that is -- in my point of few -- a very bad visualization anyway. Good luck with this attempt. – Stefan Pinnow Feb 13 '17 at 23:29
  • 1
    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
  • 1
    You can place nodes as arbitrarily as pins though. I don't see the actual benefit of pins that woudn't be possible with nodes – percusse Feb 26 '17 at 19:10

Your Answer

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

Browse other questions tagged or ask your own question.