3

How to correctly specify ticks in date plots?

I tried

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usepgfplotslibrary{dateplot}

\begin{document}

%\begin{tikzpicture}
%\begin{axis}
%\addplot coordinates{
%(1, 0)
%(2, 1)
%};
%\end{axis}
%\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[
date coordinates in=x,
xtick={
2014-01-01,
2016-01-01
},
xmin=2014-01-01,
xmax=2016-07-01
]

\addplot coordinates{
(2014-01-16, 0)
(2016-01-18, 1)
};
\end{axis}
\end{tikzpicture}

\end{document}

but it does not compile:

! Undefined control sequence.
\pgfplots@loc@TMPc ...pgfplots@calender@ZEROSHIFT 
                                                  \relax \ifx \pgfplotstempt...
l.30 ]

What's very strange: If the date plot is not the first plot (e.g., uncomment the first plot in my example), everything compiles just fine.

Is this a bug?

3

It seems like you have to specify date ZERO manually if you use custom xticks.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usepgfplotslibrary{dateplot}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
date coordinates in=x,
date ZERO=2014-01-01, % ADDED LINE
xtick={
2014-01-01,
2016-01-01
},
xmin=2014-01-01,
xmax=2016-07-01
]

\addplot coordinates{
(2014-01-16, 0)
(2016-01-18, 1)
};
\end{axis}
\end{tikzpicture}

\end{document}
2
  • This seems to work. Is it intentional or a bug? – Bloops Feb 2 '16 at 14:03
  • 1
    The documentation states "As of 1.13, the first encountered coordinate is used as date ZERO, i.e. it is assigned automatically without user intervention." So how I understand the documentation this is a bug. – Benjamin Feb 2 '16 at 14:11

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.