在 Pgfplots 中指定时间和日期

在 Pgfplots 中指定时间和日期

我有与浮点值关联的日期作为 x 数据;使用 pgfplots 绘制它们非常简单

\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}

现在我有约会了加上时间。简单地将它们添加到表中显然会导致编译失败

\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'..

那么如何指定时间?

答案1

添加逗号后我没有遇到任何问题。由于您将选项添加red到表中:您在哪里添加了col sep=commaand header=false?至少这有效:

\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}

在此处输入图片描述

相关内容