# Plot time series with PGFPlots and GNUPlot [closed]

I am trying to plot a large time series using PGFPlots, but it takes ages and often crashes with memory error, so I thought to use GNUPlot. This works fine with the same data but with simple sequential x coordinates, but when using datetimes PGFPlots can't parse GNUPlot's output.

This is a MWE:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usepgfplotslibrary{dateplot}
\begin{filecontents}{values.csv}
datetime,value
2016-01-01 00:00:00,1
2016-01-02 00:00:00,6
2016-01-05 00:00:00,3
2016-01-08 00:02:00,6
2016-01-13 00:00:00,9
2016-01-25 03:05:00,3
2016-02-05 03:04:00,7
2016-05-31 00:00:00,9
2016-12-01 12:04:00,4
\end{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
date coordinates in=x,
date ZERO=2016-01-01,
]
\addplot gnuplot [id=my_datetime_plot, raw gnuplot] {
set xdata time;
set timefmt "\%Y-\%m-\%d \%H:\%M:\%S";
set format x "\%Y-\%m-\%d \%H:\%M:\%S";
set datafile separator ",";
plot "values.csv" using 1:2 w lines;
};
\end{axis}
\end{tikzpicture}
\end{document}


After I run latex on it, the file paper.my_datetime.table is correctly populated by GNUPlot:

# Curve 0 of 1, 9 points
# Curve title: ""values.csv" using 1:2"
# x y type
"2016-01-01 00:00:00" 1.0000000e+00  i
"2016-01-02 00:00:00" 6.0000000e+00  i
"2016-01-05 00:00:00" 3.0000000e+00  i
"2016-01-08 00:02:00" 6.0000000e+00  i
"2016-01-13 00:00:00" 9.0000000e+00  i
"2016-01-25 03:05:00" 3.0000000e+00  i
"2016-02-05 03:04:00" 7.0000000e+00  i
"2016-05-31 00:00:00" 9.0000000e+00  i
"2016-12-01 12:04:00" 4.0000000e+00  i


However, now PGFPlots can't seem to parse the dates:

! Package PGF Math Error: Could not parse input '00:00:00"' as a floating point
number, sorry. The unreadable part was near ':00:00"'..


I guess it considers the line

"2016-01-01 00:00:00" 1.0000000e+00  i


as four different fields, ignoring the quotes.

I thought one quick fix would be to tell GNUPlot to export the datetime without spaces, e.g.

set format x "\%Y-\%m-\%dT\%H:\%M:\%S";


but now PGFPlots won't parse them. As far as I can tell, PGFPlots datetime format is hardcoded to

%Y-%m-%d %H:%M:%S


Am I missing something? How can I specify the datetime format?

I saw this unsolved question. In my case I can make GNUPlot output correct values, the problem seems to be within PGFPlots.

## closed as unclear what you're asking by Stefan Pinnow, Martin Schröder, Mensch, user13907, Maarten DhondtDec 18 '16 at 14:35

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• Sorry, but why do you think PGFPlots will not "crash" when you just want to plot the same data, i.e. without manipulating the number of points or whatever, but just using raw gnuplot, which will also just plot a table ... – Stefan Pinnow Dec 12 '16 at 18:49
• And the gnuplot output is not correct, because there shouldn't be any quotation marks around the date-time block, but another column separator as the space, because this is already used as a separator between the date and the time. – Stefan Pinnow Dec 12 '16 at 18:50
• Plotting with PGFPlots directly gives an out or memory error with pdflatex and just does not end with lualatex (I waited about 1 hour). I saw advices to use GNUPlot in these cases, and plotting by row index does indeed work in under 1 minute. Your comment makes sense, but then why does this happen? I'm not familiar with GNUPlot's output format (I found very little documentation about set table), but I assumed space inside quotes wouldn't count as separator, as same with commas in CSV files. – Claudio Dec 12 '16 at 19:42
• I am as well not familiar with gnuplot, so unfortunately I cannot help you there. But it sounds weird that plotting against the row index works fine but against the date does not. Could you provide the full data file so I can try myself? – Stefan Pinnow Dec 12 '16 at 19:51