1

Here is a simple datafile data.csv:

Time,Value
"2017-01-31 12:51:05",500
"2017-01-31 12:51:05",820
"2017-01-31 13:48:14",820
"2017-01-31 13:48:14",500

Here is a simple plot of it:

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    date coordinates in = x,
    set layers,
    every axis plot/.append style={on layer=pre main},
    xticklabel = {\hour:\minute},
    x tick label style = {align=center},
    xlabel = X, 
    ylabel = Y,
    ymin = 500.0,
    ymax = 820.0
]

\addplot [color = black, fill = black, opacity = 0.2, draw opacity = 0] table [y=Value, col sep = comma]{data.csv};

\end{axis}
\end{tikzpicture}
\end{document}

This works as you would expect:

enter image description here

I want to specify xmin, xmax and xtick (and need to add date ZERO apparently):

\begin{axis}[
    date coordinates in = x,
    set layers,
    every axis plot/.append style={on layer=pre main},
    xticklabel = {\hour:\minute},
    x tick label style = {align=center},
    date ZERO = 2017-01-31 08:00,
    xtick = {2017-01-31 09:30,2017-01-31 11:30,2017-01-31 13:30,2017-01-31 15:30},
    xmin = 2017-01-31 08:00,
    xmax = 2017-01-31 17:00,
    xlabel = X, 
    ylabel = Y,
    ymin = 500.0,
    ymax = 820.0
]

Now I get the following, :

Error: ! Dimension too large.<recently read> \pgf@xx \end{axis}
       ! Dimension too large.\pgf@process #1->{#1\global\pgf@x = \pgf@x\global \pgf@y = \pgf@y }\end{axis}
       …

But when I comment the \addplot, I get:

enter image description here

which is the right canvas. Why???

1

Seems to relate to the quotes around the date/time in data.txt, remove those and you get

output of code at bottom

With the quotes, the \year somehow becomes 8215, instead of 2017. Set xticklabel = {\year-\month-\day--\hour:\minute}, x tick label style = {align=center,rotate=45} to see that:

ticklabels with original data

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    date coordinates in = x,
    set layers,
    every axis plot/.append style={on layer=pre main},
    xticklabel = {\hour:\minute},
    x tick label style = {align=center},
    date ZERO = 2017-01-31 08:00,
    xtick = {2017-01-31 09:30,2017-01-31 11:30,2017-01-31 13:30,2017-01-31 15:30},
    xmin = 2017-01-31 08:00,
    xmax = 2017-01-31 17:00,
    xlabel = X, 
    ylabel = Y,
    ymin = 500.0,
    ymax = 820.0
]

\addplot [color = black, fill = black, opacity = 0.2, draw opacity = 0]
  table [y=Value, col sep = comma]{
Time,Value
2017-01-31 12:51:05,500
2017-01-31 12:51:05,820
2017-01-31 13:48:14,820
2017-01-31 13:48:14,500
};

\end{axis}
\end{tikzpicture}
\end{document}
4
  • Well thank you, never would have though this would be a problem. Why the hell does dateplot parses it properly in one case and not in the other? – Fatalize Jan 9 '18 at 14:00
  • @Fatalize It expects to get data of the form yyyy-mm-dd HH:MM, not "yyyy-mm-dd HH:MM", so with incorrect input, it is perhaps no surprise that the output is incorrect. – Torbjørn T. Jan 9 '18 at 14:03
  • It works when not specifying mins and max, so this is inconsistent. – Fatalize Jan 9 '18 at 14:06
  • @Fatalize Well, sort of works. As you can see from the part I edited into my answer, the year becomes wrong with the quotes (I can't say why), so when you specify the x-limits, the data points are actually 6200 years outside the axis limits. xmin = 8215-01-31 08:00, xmax = 8215-01-31 17:00 works with your original data. – Torbjørn T. Jan 9 '18 at 14:25

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.