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

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

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

Post by rjh2805 »

Hi all,

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

Code: Select all

1403085611	20905.2942897	93251.9372868
1403085911	19610.7392042	87720.7213289
1403086212	19784.2685653	80539.6569753
...
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:

Code: Select all

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

Code: Select all

2014-06-18 12:00:11 20.9053
2014-06-18 12:05:11 19.6107
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:

Code: Select all

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

Code: Select all

2014-06-18 12:00:11 , 20.9053
2014-06-18 12:05:11 , 19.6107
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.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

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

Post by Stefan Kottwitz »

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
LaTeX.org admin
rjh2805
Posts: 2
Joined: Sun Jul 27, 2014 12:11 pm

Re: Plotting time-series, white-space-separated data, UNIX t

Post by rjh2805 »

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?
Post Reply