LaTeX forum ⇒ Graphics, Figures & TablesPlotting time-series, white-space-separated data, UNIX time

Information and discussion about graphics, figures & tables in LaTeX documents.
rjh2805
Posts: 2
Joined: Sun Jul 27, 2014 12:11 pm

Plotting time-series, white-space-separated data, UNIX time

Postby rjh2805 » Sun Jul 27, 2014 12:29 pm

Hi all,

I'm trying to generate a plot using pgfplots, based on a data file that looks as follows:

  1. 1403085611 20905.2942897 93251.9372868
  2. 1403085911 19610.7392042 87720.7213289
  3. 1403086212 19784.2685653 80539.6569753
  4. ...


So I have a UNIX timestamp, followed some measurement values. As far as I understood, pgfplots only supports ISO-formatted date/time-strings, so I try to use [cmd]\addplot shell[/cmd], together with gawk, to convert the UNIX timestamp to an ISO-formatted date/time-string:

  1. \addplot[
  2. color = red,
  3. mark = none
  4. ] shell {gawk '/^[0-9]/{print strftime("\%Y-\%m-\%d \%H:\%M:\%S",$1), $2/1000}' data/results.log};


This yields the following results:

  1. 2014-06-18 12:00:11 20.9053
  2. 2014-06-18 12:05:11 19.6107
  3. 2014-06-18 12:10:12 19.7843


However, compilation fails now since pgfplots interprets the date and time columns as separate values. Of course, I could use awk to make the values comma-separated, like in:

  1. \addplot[
  2. color = red,
  3. mark = none
  4. ] shell {gawk '/^[0-9]/{print strftime("\%Y-\%m-\%d \%H:\%M:\%S",$1), ",", $2/1000}' data/results.log};


This yields the following results:

  1. 2014-06-18 12:00:11 , 20.9053
  2. 2014-06-18 12:05:11 , 19.6107
  3. 2014-06-18 12:10:12 , 19.7843


However, the problem with this approach is that [cmd]\addplot shell[/cmd] does not have a 'col sep=comma' option, in the same way as [cmd]\addplot table[/cmd] has it.

I know that I could use gnuplot, etc., but my goal is to keep it as simple as possible, only using pgfplots. Any suggestions on how I could get pgfplots to plot my time-series?
Last edited by rjh2805 on Tue Jul 29, 2014 7:40 am, edited 1 time in total.

Tags:

User avatar
Stefan Kottwitz
Site Admin
Posts: 8541
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Mon Jul 28, 2014 3:23 pm

Welcome to the forum!

Also I like to use pgfplots. I rarely use gnuplot, just together with pgfplots for contour plots.

I think you could run gawk, sed or any other such tool to convert to csv and read it in as a table, via \addplot table, even if \addplot shell would be more elegant.

Stefan
Site admin

rjh2805
Posts: 2
Joined: Sun Jul 27, 2014 12:11 pm

Postby rjh2805 » Tue Jul 29, 2014 7:42 am

Hi Stefan,

Using [cmd]\addplot shell[/cmd] would definitely be most elegant. However, I have no clue how to process comma-separated data using that command. Any suggestions?


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 5 guests