I want to plot some data depending on dates, but as the date range is quite large (4-5 years) I would like to have ticks in the form dd.mm\\yyyy
, is it possible ? It would be even better not to repeat the year for each tick, by displaying only year changes, but it is not a necessity 😉
Here is a working example :
\begin{tikzpicture}
\begin{axis}[
axis on top,
enlarge x limits = false,
date coordinates in=x,
xticklabel=\day.\month.\year,
date ZERO = 2013-08-13
]
\addplot[blue] coordinates {
(2013-08-13, 5)
(2013-08-18, 10)
(2013-08-21, 4)
(2013-08-26, 7)
(2013-09-01, 1)
(2013-09-02, 0)
(2013-09-06, 4)
(2013-09-11, 5.5)
(2013-09-15, 3)
(2013-11-13, 5)
(2013-11-18, 10)
(2013-11-21, 4)
(2013-12-26, 7)
(2014-01-01, 1)
(2014-01-02, 0)
(2014-01-06, 4)
(2014-02-11, 5.5)
(2014-02-15, 3)
};
\end{axis}
\end{tikzpicture}
I tried replacing xticklabel=\day.\month.\year
by xticklabel={\day.\month\\ \year}
without success.
Best Answer
Similar to axis labels and TikZ nodes in general, one way to introduce line breaks is to explicitly specify the text alignment by setting
In order to only print the year when it changes, you can store the previous label's year value in a macro and compare whether the current year label is equal to that:
Complete code