TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a datafile (which I may manipulate to any format), it contains a date-time stamp currently in the form "year-month-day hour:min" and a single variable for each recorded time.

When I attempt to plot this datafile it is parsed as if the date-time stamp is two variables, my question is how should I be formatting the datafile for it to be parsed as a single variable.


share|improve this question
up vote 16 down vote accepted

You should use commas to separate the fields. Then you can plot the file using \addplot table [col sep=comma] {datafile.csv};

If you want to use whitespaces in addition to the commas to keep the file more readable, you need to use [col sep=comma,trim cells=true] to strip the spaces around the commas.

Here's a minimal example of plotting a file with dates and times:



date coordinates in=x,
xticklabel={\day.\month.\year\\ \hour:\minute},
x tick label style={align=center},
date ZERO=2010-01-01, % Set near lowest date
xmin={2010-01-01}, % A date with no time is assumed to have a time of 00:00
xtick={2010-01-01 12:00, % Set tick marks
2010-01-02 12:00,
2010-01-03 12:00}
\addplot table [col sep=comma,trim cells=true,y=value1] {data.csv};
\addplot table [col sep=comma,trim cells=true,y=value2] {data.csv};


With a datafile.csv like this:

date,                   value1, value2
2010-01-01 12:00,       2,      0
2010-01-01 23:15,       10,     1
2010-01-03 12:00,       8,      10

would yield the following output:

PGFplots plot of datafile with dates

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.