I would like to plot quarterly time series with special x-axis features. In particular, I would like to see small ticks indicating when the quarters begin and larger ticks indicating when the years begin, but would only like to label the years (and not the quarters). For illustration purposes, the following example does exactly what I want, except that the code is not flexible at all.
\documentclass{article}
\usepackage{pgfplots}
\usepackage{filecontents}
\pgfplotsset{width=8cm,compat=newest}
\usepgfplotslibrary{dateplot}
\usetikzlibrary{calc}
\begin{filecontents}{Quarterly.dat}
date Y
2009-02-15 1
2009-05-15 2
2009-08-15 3
2009-11-15 4
2010-02-15 4
2010-05-15 4
2010-08-15 4
2010-11-15 4
2011-02-15 4
2011-05-15 4
2011-08-15 4
2011-11-15 4
2012-02-15 4
2012-05-15 4
2012-08-15 4
2012-11-15 4
2013-02-15 4
2013-05-15 4
2013-08-15 4
2013-11-15 4
\end{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
mark =none,
xmin=2008-12-01,
xmax=2012-02-01,
major tick length=4pt,
minor tick length=2pt,
date coordinates in=x,
minor x tick num=3,
xtick={2009-01-01,2010-01-01,2011-01-01,2012-01-01},
xticklabels= {\year,\year,\year},
x tick label style={anchor=east,xshift=1.5cm,yshift=-0.3cm},
]
\addplot [only marks,green]table [x=date,y=Y]{Quarterly.dat}; %
\end{axis}
\end{tikzpicture}
\end{document}
The code is not flexible for several reasons. For instance, if I write xtick={2009-01-01,2010-01-01,2011-01-01,2012-01-01,2013-01-01}, the minor x tick num=3 stops working (probably because the ticks don’t have the same distance). The example also requires that I have to manually set xshift (in the example xshift=1.5cm). It would be great if the code could automatically lable all years for any quarterly time series. I also tried to use the extra x ticks option, but without success.


x tick label as intervaloption. And replacing2013-01-01by2013-01-00fixes your problem. – Symbol 1 Dec 31 '14 at 08:48