# Specify times and dates in Pgfplots

I have x-data as dates associated with float values; plotting them with pgfplots is as easy as

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\begin{document}
\begin{tikzpicture}

\begin{axis}[
date coordinates in=x,
xticklabel style={rotate=90,anchor=near xticklabel},
xticklabel=\year-\month-\day
]
2016-10-10 50
2016-10-11 56
};
\end{axis}

\end{tikzpicture}
\end{document}


Now, I have dates plus times. Simply adding them to the table obviously results in a failed compilation

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\begin{document}
\begin{tikzpicture}

\begin{axis}[
date coordinates in=x,
xticklabel style={rotate=90,anchor=near xticklabel},
xticklabel=\year-\month-\day
]
2016-10-10 13:10 50
2016-10-11 12:55 56
};
\end{axis}

\end{tikzpicture}
\end{document}

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


How to specify times then?

• Are you looking for tex.stackexchange.com/a/445564/121799 ?
– user121799
Mar 20, 2019 at 16:31
• @marmot It should be much easier than that; Pgfplot does support times after all. Mar 20, 2019 at 16:40
• Yes, but you have to help pgfplots then to judge whether a space separates the time from the day or a column.
– user121799
Mar 20, 2019 at 16:48
• @marmot Indeed. I wouldn't mind adding commas with a col sep, but that doesn't work either. Mar 20, 2019 at 17:16

I do not have any problems after adding a comma. Since you added the option red to the table: where did you add col sep=comma and header=false? At least this works:

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\begin{document}
\begin{tikzpicture}

\begin{axis}[
date coordinates in=x,
xticklabel style={rotate=90,anchor=near xticklabel},
xmin=2016-10-10 00:00,
xmax=2016-10-12 00:00,
xticklabel=\year-\month-\day
]

• Great, I'd been missing header=false. Mar 20, 2019 at 23:33