1

I have a problem implementing a tikzpicture. I want to plot the file with date and TIME and a climatic variable. I followed the PGF manual in section 4.21.2 "Dates as Input Coordinates" and if i do the table of the coordinates "by hand", everything works as intended:

    \begin{tikzpicture}
            \begin{axis}[
            date coordinates in=x,
            xtick=data,
            xticklabel style=
            {rotate=90,anchor=near xticklabel},
            xticklabel={\day.\month.},
            xlabel={2015},
            date ZERO=2015-01-01,% <- improves precision!
            ]
                    \addplot coordinates {
                    (2015-12-21 00:00, 17.54)
                    (2015-12-21 00:59, 17.23)
                    (2015-12-21 01:58, 16.96)
                    (2015-12-21 02:57, 16.88)
                    (2015-12-21 03:56, 16.70)
                    (2015-12-21 04:55, 16.36)
                    (2015-12-21 05:54, 17.02)
                    (2015-12-21 06:53, 19.24)
                    (2015-12-21 07:52, 20.40)
                    (2015-12-21 08:51, 22.06)
                    };
            \end{axis}
    \end{tikz

But when the parser has to look for the file, as in here:

    \begin{tikzpicture}
            \begin{axis}[
            date coordinates in=x,
            xtick=data,
            xticklabel style=
            {rotate=90,anchor=near xticklabel},
            xticklabel={\day.\month.},
            xlabel={2015},
            date ZERO=2015-01-01,% <- improves precision!
            ]
            \addplot table[x=date,y=temperature] {plotdata/temp_summer.dat};
            \end{axis}
    \end{tikzpicture}

then the following error appears:

! Package PGF Math Error: Could not parse input '00:00,' as a floating point number, sorry. The unreadable part was near ':00,'..
See the PGF Math package documentation for explanation. Type  H <return>  for immediate help.
 ...
l.421 ...=temperature] {plotdata/temp_summer.dat};

I get the error messages about the 00:00 or any other hour. The funny thing that it is working if I introduced the coordinates in the .tex file itself.

Í suspect this is a BUG in PGF file parser but I'm not sure, my .tex system is:

pdfTeX, Version 3.1415926-2.5-1.40.14 (MiKTeX 2.9 64-bit)

Package pgfplots notification 'compat/show suggested version=true': document has been generated with the most recent feature set (\pgfplotsset{compat=1.13}).

Let me tell you guys that if I removed the HH:MM then, the file compilation is successful but then, is not what I need!.

Any ideas, any help is GREATLY appreciated.

Thank you in advance.....

  • Welcome! Please make your code compilable or, in the second case, such that when we try to compile it, we'll get the same error you get. To do this, you need to make the fragments into complete mini-documents and to provide some sample data for the second one. – cfr Jun 23 '16 at 15:13
  • That is, did you adjust the format of the data appropriately? It will not be expecting coordinates from the file. It will be expecting data from which to construct the coordinates. At least, I think so. I'm assuming you are using pgfplots and that seems to be how it works, though I'm not terribly familiar with it. – cfr Jun 23 '16 at 15:16
1

Here is a MWE

\begin{filecontents*}{data.dat}
date, temperature
2015-12-21 00:00, 17.54
2015-12-21 00:59, 17.23
2015-12-21 01:58, 16.96
2015-12-21 02:57, 16.88
2015-12-21 03:56, 16.70
2015-12-21 04:55, 16.36
2015-12-21 05:54, 17.02
2015-12-21 06:53, 19.24
2015-12-21 07:52, 20.40
2015-12-21 08:51, 22.06
\end{filecontents*}
\documentclass[margin=5pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}
        \begin{axis}[
        date coordinates in=x,
        xtick=data,
        xticklabel style=
        {rotate=90,anchor=near xticklabel},
        xticklabel={\day.\month. \hour:\minute},
        xlabel={2015},
        date ZERO=2015-01-01,% <- improves precision!
        ]
        \addplot table[x=date,y=temperature,col sep=comma] {data.dat};
        \end{axis}
\end{tikzpicture}
\end{document}

which results in

enter image description here

Note that you have to use col sep=comma as option of table if the column sep in your file is a comma:

\addplot table[x=date,y=temperature,col sep=comma] {data.dat};

Then the comma must also be used as seperator between the column headers: date, temperature. I guess this , is missing in your file.

  • Indeed my friend, you are perfectly right. The problem is that the table file generated by matlab have the first row WITHOUT the comma. Huge thanks! and regards. – Sergio Alejandro González Jul 6 '16 at 14:47
  • @SergioAlejandroGonzález Maybe you can accept the answer if it solves your problem. – esdd Jul 6 '16 at 18:51

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.