1

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

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}

\begin{axis}[
  date coordinates in=x,
  xticklabel style={rotate=90,anchor=near xticklabel},
  xticklabel=\year-\month-\day
]
\addplot table [red] {%
  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}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}

\begin{axis}[
  date coordinates in=x,
  xticklabel style={rotate=90,anchor=near xticklabel},
  xticklabel=\year-\month-\day
]
\addplot table [red] {%
  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?

4
  • Are you looking for tex.stackexchange.com/a/445564/121799 ? – user121799 Mar 20 '19 at 16:31
  • @marmot It should be much easier than that; Pgfplot does support times after all. – Nico Schlömer Mar 20 '19 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 '19 at 16:48
  • @marmot Indeed. I wouldn't mind adding commas with a col sep, but that doesn't work either. – Nico Schlömer Mar 20 '19 at 17:16
1

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}
\pgfplotsset{compat=newest}
\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
]
\addplot[only marks] table [col sep=comma,header=false] {%
  2016-10-10 13:10,50
  2016-10-11 12:55,56
};
\end{axis}

\end{tikzpicture}
\end{document}

enter image description here

1
  • Great, I'd been missing header=false. – Nico Schlömer Mar 20 '19 at 23:33

Your Answer

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

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