2

I tried to read a file with time and date on x axis but it gives an error as "could not parse input "00:00:19" as floating point number"

I saved the excel file with "tab delimited" extension. I also put table/col sep as space.

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

I could not find option to upload a text file here, so here is the sample

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
  • isn't the data being split at spaces? so here you do not have x and y coords, but x, y and z coords. You'll probably need "..." or similar. – daleif Jun 7 '18 at 10:45
4

You're using a space as the column separator, and you have a space between yyyy-mm-dd and HH:MM:SS. So yyyy-mm-dd is read as the x-column, and HH:MM:SS as the y-column. Use something like

x,y
2018-05-18 00:00:19, -59
2018-05-18 00:01:01, -59

and

\addplot [...] table[col sep=comma] {...

Note by the way that the precision of the dateplot library is limited, so the seconds value is always ignored, and taken as zero. Hence,

2018-05-18 00:04:03 -56
2018-05-18 00:04:25 -60
2018-05-18 00:04:46 -58

is the same as

2018-05-18 00:04:00 -56
2018-05-18 00:04:00 -60
2018-05-18 00:04:00 -58

For that reason you can see in the image below that there are several cases of multiple markers at the same x-value. Depending on the amount and range of your data this may or may not be a problem. I note you have mark repeat=15, so I'm guessing it won't be much of a problem.

enter image description here

\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}
4
  • Thank you so much for your answer but I have already tried this and could not get required output. I put comma after time and than saved the excel file with tab delimited extension however, it automatically added quotations around date and time like this "2018-05-18 00:04:03," -56 . So in order to avoid it i simply copy the excel data and saved it in notepad. However, it still gives error "could not retrieve column x from table" – Tayyaba Liaqat Jun 7 '18 at 11:25
  • @TayyabaLiaqat Did you put the comma in the actual cells in Excel? That's the wrong way to go about it, surely you can select the column delimiter when you save as CSV from Excel? If you use the exact format I show at the start of my answer, does it not work then? (With col sep=comma, of course.) – Torbjørn T. Jun 7 '18 at 11:29
  • @TayyabaLiaqat I don't really understand what you're saying, I certainly haven't suggested putting the data in the tex file. In essence, what I'm saying is that you have to use something else than a space to separate the date column from the y-column, that is your only problem. (The file extension is also not really important, what's important is how the plain text file with data is formatted.) – Torbjørn T. Jun 8 '18 at 7:31
  • Thank you for your help. I just solved the problem by saving excel file in CSV format, than opened CSV file via Notepad and saved it as txt file. Finally I read this txt file in tex file and it runs successfully. – Tayyaba Liaqat Jun 8 '18 at 7:35

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.