我尝试读取 x 轴上有时间和日期的文件,但它给出了一个错误“无法将输入“00:00:19”解析为浮点数”
我使用“制表符分隔”扩展名保存了 excel 文件。我还将表/列分隔符设置为空格。
\documentclass[conference]{IEEEtran}
\ifCLASSINFOpdf
\else
\fi
\hyphenation{op-tical net-works semi-conduc-tor}
\usepackage[pdftex]{graphics}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepgfplotslibrary{dateplot}
\usepgfplotslibrary{patchplots}
\pgfplotsset{compat=1.7}
\hyphenation{op-tical net-works semi-conduc-tor}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
xlabel=Time (hr:min),
ylabel=RSSI,
height=5cm, width=8cm,
legend cell align=left, legend columns=-1, legend style={inner xsep=2pt, inner ysep=2pt,at={(0.35,0.1)},anchor=east,font=\tiny},
mark repeat={15},
label style={font=\small},
date coordinates in=x,
table/col sep=space,
% date ZERO=2010-01-1,
% xticklabel= \hour:\minute,
% xticklabel style={anchor=near xticklabel},
ymin=-75, ymax=-55, ytick={-75,-70,-65,-60,-55},
]
\addplot [only marks, mark size=1.4pt,mark=+,red!90!black] table[x=x, y=y] {RSSI.txt};
%\addplot [only marks, mark size=1.4pt,mark=asterisk,blue!80!black] table[x=x, y=y] {time-rssi-ch17x-2.txt};
%\addplot [only marks, mark size=1.4pt,mark=o,green!90!black] table[x=x, y=y] {time-rssi-ch26x-2.txt};
\legend{Ch-15,Ch-17,Ch-26}
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
我找不到此处上传文本文件的选项,因此这里是示例
x y
2018-05-18 00:00:19 -59
2018-05-18 00:01:01 -59
2018-05-18 00:01:31 -59
2018-05-18 00:02:17 -59
2018-05-18 00:02:40 -59
2018-05-18 00:03:17 -58
2018-05-18 00:03:32 -60
2018-05-18 00:04:03 -56
2018-05-18 00:04:25 -60
2018-05-18 00:04:46 -58
2018-05-18 00:05:44 -59
2018-05-18 00:06:08 -59
2018-05-18 00:06:41 -58
2018-05-18 00:07:09 -59
2018-05-18 00:07:20 -60
2018-05-18 00:08:05 -59
2018-05-18 00:08:31 -60
2018-05-18 00:09:06 -59
2018-05-18 00:09:25 -59
2018-05-18 00:10:00 -54
2018-05-18 00:10:42 -54
答案1
您使用空格作为列分隔符,并且yyyy-mm-dd
和之间有一个空格HH:MM:SS
。因此yyyy-mm-dd
读作 x 列, 读HH:MM:SS
作 y 列。使用类似
x,y
2018-05-18 00:00:19, -59
2018-05-18 00:01:01, -59
和
\addplot [...] table[col sep=comma] {...
顺便说一下,dateplot 库的精度是有限的,所以秒值总是被忽略,并被视为零。因此,
2018-05-18 00:04:03 -56
2018-05-18 00:04:25 -60
2018-05-18 00:04:46 -58
是相同的
2018-05-18 00:04:00 -56
2018-05-18 00:04:00 -60
2018-05-18 00:04:00 -58
因此,您可以在下图中看到,有几种情况,多个标记位于相同的 x 值。根据数据的数量和范围,这可能是也可能不是问题。我注意到您有mark repeat=15
,所以我猜这不会是太大的问题。
\documentclass[conference]{IEEEtran}
\usepackage{pgfplotstable} % loads pgfplots
\usepgfplotslibrary{dateplot}
\pgfplotsset{compat=1.7}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
xlabel=Time (hr:min),
ylabel=RSSI,
height=5cm, width=8cm,
legend cell align=left,
legend columns=-1,
legend style={
inner xsep=2pt,
inner ysep=2pt,
at={(0.35,0.1)},
anchor=east,
font=\tiny
},
% mark repeat={15}, % commented for sake of example
label style={font=\small},
date coordinates in=x,
date ZERO=2018-05-18,
xticklabel= \hour:\minute,
% xticklabel style={anchor=near xticklabel},
% ymin=-75, ymax=-55, ytick={-75,-70,-65,-60,-55}, % commented for sake of example
table/col sep=comma % commma, not space
]
\addplot [only marks, mark size=1.4pt,mark=+,red!90!black] table[x=x, y=y] {RSSI.txt};
%\addplot [only marks, mark size=1.4pt,mark=asterisk,blue!80!black] table[x=x, y=y] {time-rssi-ch17x-2.txt};
%\addplot [only marks, mark size=1.4pt,mark=o,green!90!black] table[x=x, y=y] {time-rssi-ch26x-2.txt};
\legend{Ch-15,Ch-17,Ch-26}
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}