Menu

#96 dateplot - values shifted by 1 day

v1.0 (example)
closed
nobody
None
5
2016-01-02
2015-11-09
Torbjorn
No

I don't know what causes this, but I can't really see anything wrong with the code, so it looks like a bug. It comes from tex.stackexchange.com/questions/277311/

The code and output is as follows:

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\usepackage{filecontents}
\begin{filecontents*}{data.csv}
date,value
2015-01-01, 3.2
2015-01-04, 6.5
2015-01-10, 6.8
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\centering
\begin{axis}[
    date coordinates in=x,
    xticklabel={\day-\month},
% either of the following two options fixes the problem
%    xtick=data
%    date ZERO=2015-01-01
]
\addplot table [x=date, y=value, col sep=comma] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}

output of above code

As you can see the points are one day to the left of the corresponding ticks, e.g. the last point for January 10 is placed on January 9.

Discussion

  • Torbjorn

    Torbjorn - 2015-11-09

    Oops, sorry about the size of the image, and lack of hyperlink. Doesn't appear to be possible to edit either.

     
  • Christian Feuersänger

    Thanks for the report.

    I see the problem, and I can explain it.

    I'll have to think about ways to solve it.

    The problem becomes apparent with additional debug logging. Apparently, the automatic tick computation results in the following numeric representations of the tick labels:

    3287.9985000000000->2015-01-01, 23:58
    3289.9985000000000->2015-01-03, 23:58
    3291.9985000000000->2015-01-05, 23:58
    3293.9985000000000->2015-01-07, 23:58
    3295.9985000000000->2015-01-09, 23:58

    xtick=data results in

    3287.000000000->2015-01-01, 0:0
    3290.00000000->2015-01-04, 0:0
    3296.000000000->2015-01-10, 0:0

    Thus, it is an accuracy issue combined with the special string to number mapping of the dateplot lib.

    Note that if you use a non-date plot with the x coordinates 3287, 3290, and 3296, the tick labels are fine -- since they are rounded. If the dateplot lib would also round to full days, all would be fine as well... perhaps I need to round to 2 digits before I map back to date strings?

     
  • Christian Feuersänger

    Another possible solution may be to ensure that 'date ZERO' is set to a useful value, even if the user did not provide one.

     
  • Christian Feuersänger

    • status: open --> closed
     
  • Christian Feuersänger

    I have ensured that 'date ZERO' is set to the first encountered date if it is not set manually.

    This appears to solve the issue.

    The fix will be part of pgfplots 1.13