![从 txt 导入时间:“扫描 \pgfplotslibdateplot@map@time 的使用时文件结束。”](https://linux22.com/image/407085/%E4%BB%8E%20txt%20%E5%AF%BC%E5%85%A5%E6%97%B6%E9%97%B4%EF%BC%9A%E2%80%9C%E6%89%AB%E6%8F%8F%20%5Cpgfplotslibdateplot%40map%40time%20%E7%9A%84%E4%BD%BF%E7%94%A8%E6%97%B6%E6%96%87%E4%BB%B6%E7%BB%93%E6%9D%9F%E3%80%82%E2%80%9D.png)
我在使用时间轴和从 txt 文件导入的数据时遇到问题。
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot, statistics}
\pgfplotsset{compat=newest}
\usepackage{filecontents}
\begin{filecontents*}{data2.txt}
09:04:08 887.2999878
09:04:09 887.2999878
09:04:10 887.4000244
09:04:11 887.4000244
09:04:12 887.4000244
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
date coordinates in = x,
xticklabel = \hour:\minute]
\addplot [draw=none] table[col sep = space] {data2.txt};
\end{axis}
\end{tikzpicture}
\end{document}
每当我运行此代码时,我都会收到错误:扫描使用 \pgfplotslibdateplot@map@time 时文件结束。
我不知道哪里出了问题,因为我认为我正确地结束了所有命令。
提前感谢任何帮助
*编辑了一些不必要的代码
答案1
我认为该库不支持没有日期的时间。这对我来说有用:
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot, statistics}
\pgfplotsset{compat=newest}
%\usepackage{filecontents} %not needed in new latex
\begin{filecontents*}[overwrite]{data2.txt} %overwrite needs new latex
2020-01-27 09:04:08, 887.2999878
2020-01-27 09:04:09, 887.2999878
2020-01-27 09:04:10, 887.4000244
2020-01-27 09:04:11, 887.4000244
2020-01-27 09:04:12, 887.4000244
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
date coordinates in = x,
xticklabel = \hour:\minute
]
\addplot [draw=none] table[col sep = comma] {data2.txt};
\end{axis}
\end{tikzpicture}
\end{document}