2

My aim is to plot a timeseries (experimental data) using pgfplots in LaTeX (pdfLaTeX, TexLive on Mac). The data I'm using is seperated with semicolons (columnwise) and has the following structure:

-- some additional information here --

time;val1;val2;val3
sec;unit1;unit2;unit3
0.0000;1.0000;5.0000;560.0000
1.0000;7.0000;14.0000;845.0000
2.0000;5.0000;28.0000;874.0000
3.0000;9.0000;30.0000;125.0000
4.0000;12.0000;4.0000;359.0000
5.0000;25.0000;17.0000;254.0000
-- further data --
10630.0000;13.0000;27.0000;679.0000

As you can see, my timestamp is in elapsed seconds since the experiment started. Because they took some time it is unhandy to simply use seconds as a x axis label. Furthermore I have to convert the elapsed time from seconds to corresponding hours, minutes and seconds (HH:MM:SS).

My first plan was to use Gnuplot and import the data file using "%s" as timefmt to do the conversion into HH:MM:SS. This implies that every experiment would start at 1970-01-01 00:00:00 which isn't a problem because they do not take longer than a day, so the elapsed time is just a question of defining the beginning of the experiment. However I was not happy with the visual results getting out of Gnuplot.

Customizing layout and design of the plotted diagram becomes much easier when using pgfplots. There are several examples of plotting timeseries in the manual, but in contrast to my case they are only using small "amounts" of elapsed seconds, so that it isn't necessary to use HH:MM:SS as the timeformat. Therefore I'm looking for a convenient way to plot my data using pgfplots, especially converting the timestamp in the needed format.

So is there a way to plot timeseries with pgfplots and convert elapsed seconds to HH:MM:SS directly (without converting the timestamp with perl, python or awk)?

Any hint would be appreciated.

--- edit ---

I was asked to deliver a MWE. Here it is:

mwe.tex:

\documentclass{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.6}

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[width=\textwidth, height=0.6\textwidth, no markers, xlabel = time, ylabel = values]
            \addplot table[col sep = semicolon, x = time, y = val1] {mwe.dat};
        \end{axis}
    \end{tikzpicture}
\end{document}

mwe.dat:

time;val1;val2;val3;val4;val5;val6;val7
0.0000;988.9041;386.0514;60.9407;999.7958;0.0000;0.0000
1.0000;989.7011;386.0415;60.9728;976.1486;0.0000;0.0000
2.0000;990.0765;385.9371;60.9987;952.5087;0.0000;0.0000
3.0000;990.4712;385.8035;61.0285;928.8734;0.0000;0.0000
4.0000;990.9448;385.5937;61.0698;905.2437;0.0000;0.0000
5.0000;990.6617;385.4375;61.0748;881.6223;0.0000;0.0000
6.0000;989.9383;385.3135;61.0587;858.0044;0.0000;0.0000
7.0000;988.5733;385.1901;61.0135;833.6808;0.0000;0.0000
8.0000;987.3644;385.0865;60.9733;806.8475;0.0000;0.0000
9.0000;986.4483;385.0294;60.9415;780.0141;0.0000;0.0000
10.0000;986.0016;385.0210;60.9238;753.1808;0.0000;0.0000
11.0000;985.8277;385.0401;60.9147;726.3475;0.0000;0.0000
12.0000;984.4391;385.1332;60.8492;723.1921;0.0000;0.0000
13.0000;983.3045;385.2164;60.7955;728.9315;0.0000;0.0000
14.0000;982.8382;385.2735;60.7722;734.7187;0.0000;0.0000
15.0000;982.9965;385.3436;60.7717;740.5941;0.0000;0.0000
16.0000;983.4755;385.4198;60.7830;746.5047;0.0000;0.0000
17.0000;984.9704;385.6830;60.8148;752.4778;0.0000;0.0000
18.0000;986.2632;385.9315;60.8405;758.4951;0.0000;0.0000
19.0000;987.0770;386.1411;60.8520;764.5697;0.0000;0.0000
20.0000;987.3939;386.3976;60.8385;770.7164;0.0000;0.0000
21.0000;987.4412;386.6834;60.8108;776.8907;0.0000;0.0000
22.0000;987.9269;387.0912;60.7888;783.1180;0.0000;0.0000
23.0000;988.1399;387.3974;60.7663;789.3953;0.0000;0.0000
24.0000;987.8219;387.4927;60.7442;795.7339;0.0000;0.0000
25.0000;988.0637;386.9380;60.8090;802.1863;0.0000;0.0000
26.0000;988.5963;386.0614;60.9175;808.6687;0.0000;0.0000
27.0000;987.6652;385.7920;60.9090;815.1513;0.0000;0.0000
28.0000;986.6169;385.6135;60.8860;821.6718;0.0000;0.0000
29.0000;985.3884;385.5848;60.8385;828.2465;0.0000;0.0000
30.0000;985.4399;385.5550;60.8437;834.8711;0.0000;0.0000
31.0000;986.2023;385.5266;60.8778;841.5231;0.0000;0.0000
32.0000;986.9324;385.4412;60.9145;848.2865;0.0000;0.0000
33.0000;987.5075;385.3449;60.9463;855.0678;0.0000;0.0000
34.0000;987.7267;385.2306;60.9663;861.8730;0.0000;0.0000
35.0000;987.6674;385.1904;60.9675;886.9654;0.0000;0.0000
36.0000;987.4361;385.1904;60.9575;916.8582;0.0000;0.0000
37.0000;987.4476;385.3017;60.9467;947.5736;0.0000;0.0000
38.0000;987.5697;385.4517;60.9363;978.3246;0.0000;0.0000
39.0000;987.9338;385.6803;60.9278;1009.1204;0.0000;0.0000
40.0000;987.7699;385.9028;60.9005;1039.9814;0.0000;0.0000
41.0000;987.2990;386.1220;60.8622;1070.8631;0.0000;0.0000
42.0000;988.3801;386.4268;60.8735;1101.7662;0.0000;0.0000
43.0000;989.3858;386.7080;60.8840;1132.7088;0.0000;0.0000
44.0000;990.1323;386.9273;60.8908;1163.7107;0.0000;0.0000
45.0000;990.7607;387.1280;60.8950;1194.7748;0.0000;0.0000
46.0000;991.3162;387.3188;60.8977;1225.8631;0.0000;0.0000
47.0000;991.1619;387.5554;60.8675;1256.9812;0.0000;0.0000
48.0000;990.6974;387.7468;60.8295;1288.1291;0.0000;0.0000
49.0000;989.6294;387.8324;60.7783;1319.3191;0.0000;0.0000
50.0000;988.8349;387.9233;60.7372;1350.5206;0.0000;0.0000
51.0000;988.1823;388.0189;60.7010;1381.7315;0.0000;0.0000
52.0000;988.3326;387.9931;60.7097;1412.9950;0.0000;0.0000
53.0000;988.5325;387.9609;60.7210;1444.2736;0.0000;0.0000
54.0000;988.8032;387.9228;60.7355;1475.5712;0.0000;0.0000
55.0000;988.9989;387.9708;60.7383;1506.9010;0.0000;0.0000
56.0000;989.1569;388.0661;60.7350;1538.2455;0.0000;0.0000
57.0000;989.0603;387.4017;60.7977;1569.6309;0.0000;0.0000
58.0000;988.9272;386.1502;60.9180;1601.0924;0.0000;0.0000
59.0000;988.7421;383.7395;61.1525;1632.6452;0.0000;0.0000
60.0000;988.4541;380.8603;61.4303;1664.2852;0.0000;0.0000

Unfortunately I realized that plotting those 10.000 somewhat datapoints is not possible out of the box because LaTeX-Memory is too small.
Due to that I will switch back to gnuplot and use the standalone terminal function with tikz. However, after reading the manual of pgfplots again, it doesn't seem that pgfplots is able to convert seconds to HH:MM:SS. Furthermore pgfplots needs timestamps in YYYY-MM-DD HH:MM and seconds are always zero, according to the manual.

Do you have any idea how to combine the huge advantages of customizing the diagram's layout of pgfplots with gnuplot?

  • Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. Also, you don't have to sign with your name since it automatically appears in the lower right corner of your post. – darthbith Aug 28 '14 at 21:31
  • You could do the conversion manually if you have to... divide by 3600 to get the hours, then multiply the decimal by 60 to get the minutes, then multiply the decimal of that by 60 to get the leftover seconds – darthbith Aug 28 '14 at 21:35
  • This question is closely related to tex.stackexchange.com/questions/198706/… . Could you edit the question to stress what remains to be done? – Christian Feuersänger Aug 31 '14 at 17:58
  • @ChristianFeuersänger: First I simply wanted to plot my data, not concerning the timestamps. But after that it seemed that pgfplots is not able to handle timestamps in seconds. Beeing such a great tool, I couldn't believe this and decided to ask some experts here. I read through the manual stating that timestamps need to be in ISO-format (pp. 331f., 2014/08/04) with zero seconds. Knowing that gnuplot offers the capability to handle epoch timestamps (in seconds), I wanted to find a workaround using gnuplot in combination with pgfplots' "gnuplot raw" option which leads into my related question. – albert Aug 31 '14 at 21:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.