# how to cope with badly formatted pgfplots data files

I have a data file with some not very pgfplots-friendly formatting that I would like to use for a pgfplots graphic regardless. Of course, I could go and sanitize the file myself, but I'm interested in how far I can take pgfplots to do the job for me.

The file describes the Luminosity recorded by the LHC in 2011. I would like to plot two data rows, one with the ATLAS_lui and one with the CMS_lui column as a y-coordinate. The x coordinate should be the tstop column, if possible converted to human readable date - the times are currently in epoch format.

Ideally, the output would look somewhat like the plots produced by the LHC programme coordination.

My first attempt looked like this:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot table [skip first,col sep=space,x=tstop, y=ATLAS_lui] {luminosity_data_pp.txt};
\addplot table [skip first,col sep=space,x=tstop, y=CMS_lui] {luminosity_data_pp.txt};
\end{axis}
\end{tikzpicture}
\end{document}


But I get the following error:

 Package pgfplots Error: Sorry, could not retrieve column 'tstop' from table '\\pgfplotstableread@filename@@table@name '. Please check spelling (or introduce name aliases)..


• The column isn't found, because the header line starts with a table/comment chars which can not be "disabled". So just remove #  from the second line in luminosity_data_pp.txt and this error should disappear. If you don't want to modify the data file you can also use x index/y index to provide the columns. (Also remove skip first from the \addplot command, because that belongs to the \addplot file handler.) – Stefan Pinnow Nov 6 '16 at 20:42
• That works nicely, thanks! I wasn't aware that there was a comment option for text file reading. Any suggestion on the epoch format conversion issue? – carsten Nov 6 '16 at 20:49
• Have a look at <epochconverter.com/batch>. And then search here for "pgfplots time date" and you will find links like <tex.stackexchange.com/a/9734/95441> where you will find out on how to plot "the new time format". – Stefan Pinnow Nov 6 '16 at 21:02

\documentclass{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.14}

# lui = integrated luminosity in 1/ub; pui = peak luminosity in Hz/ub; time = UNIX UTC time; file generated Wed, 20 Jun 2012 22:40:08 UTC
# fill  tstart  tstop  ATLAS_lui  CMS_lui  LHCb_lui  ALICE_lui  ATLAS_plu  CMS_plu  LHCb_plu  ALICE_plu
1613  1300035889  1300063383      27381      26049      10158         0    1.30    1.39    0.47    0.00
1615  1300075970  1300083688      39022      37587      14573         0    1.65    1.71    0.64    0.00
1616  1300095655  1300117815      65933      61994      26058       101    1.78    1.86    0.70    0.02
1617  1300150745  1300161308      81018      78175      32586       441    1.54    1.67    0.66    0.02
1622  1300237772  1300260705     110167     108190      44187       919    1.45    1.54    0.59    0.03
1634  1300457119  1300478736     698067     664470     253021      5829   31.96   32.95   11.02    0.52
1635  1300487437  1300487820     704801     674492     254008      5882   31.10   36.31    3.92    0.20
1636  1300505840  1300527464    1311508    1302886     467860     13853   33.25   34.66   11.58    0.43
1637  1300537131  1300561212    2685016    2714737     954518     32135   68.93   71.39   24.31    6.51
1638  1300571103  1300596657    4093865    4171909    1432220     42325   67.55   70.61   22.49    0.81
1639  1300617669  1300640469    5382627    5478189    1879623     50320   68.08   70.51   23.66    0.78
1640  1300653093  1300683858    9212942    9366039    3019128     65373  158.12  160.76   45.50    9.03
1642  1300716807  1300740358   11651952   11619201    3818686     96817  122.88  125.97   41.50    2.80
}\mytable

\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot table [x index=3, y index=4] {\mytable};
\addplot table [x index=3, y index=4] {\mytable};
\end{axis}
\end{tikzpicture}
\end{document}


• I think you need to start the column enumeration with index 0 instead of index 1, but other than that, it works beautifully, thanks! Any suggestion on how to convert the dates from epoch to something readable? – carsten Nov 6 '16 at 20:52
• @carsten I don't know anything about that format unfortunately – percusse Nov 6 '16 at 20:55
• There seems to be some magical package for this already... tex.stackexchange.com/questions/287719/… - I'll try to figure out how it works from the documentation, but right now, it seems rather cryptic... – carsten Nov 6 '16 at 20:58