[Tex/LaTex] pgfplots: Fixing overlapping X axis labels

dateplotlabelspgfplotsticks

I am trying to create a time series plot but my X axis labels overlap:

\documentclass{article}
\usepackage{pgfplots}   
\pgfplotsset{width=14cm,compat=newest}   
\usepgfplotslibrary{dateplot}     

\begin{filecontents*}{data.csv}
count  date
38  2015-01-28
5  2015-02-11
21  2015-02-15
1  2015-02-16
21  2015-02-17
21  2015-02-18
62  2015-02-19
16  2015-02-25
4  2015-02-26
1  2015-02-30
1  2015-03-07
44  2015-04-07
\end{filecontents*}

\begin{document}
\begin{tikzpicture}
\pgfplotstableread{data.csv}\table
\begin{axis}[
    date coordinates in = x,
    date ZERO = 2015-01-28,
    ymin = 0,
    x tick label style = {font = \small, text width = 1.7cm, align = center, rotate = 70, anchor = north east},
    xtick = data,
    xticklabels from table = \table{date}
    ]
\addplot [only marks, blue] table [x = date, y = count] \table;%
\addplot [green] table [x = date, y = count] \table;%
\end{axis}
\end{tikzpicture}
\end{document} 

Removing the xtick = data, line fixes the overlapping problem, but the blue dots and the ticks on the X axis do not line up anymore.

How to have the X axis labels in constant distances? I also tried xticklabel style={inner sep=0pt, anchor=north east, rotate=70} but it did not fixed the problem.

Best Answer

This seems to work. I removed the dateplot stuff, and instead of x=date for the \addplot, I used x expr=\coordindex. This uses the index of the coordinate instead, i.e. 0,1,2,..., which gives constant distance between ticks. xtick=data places the ticks at the right place. You do need to load pgfplotstable to use x expr=\coordindex.

As a sidenote, compat=newest isn't necessarily a good thing, see Dos and Don'ts of \pgfplotsset{compat=newest}

enter image description here

\documentclass{article}
\usepackage{pgfplots,pgfplotstable}
\usepackage{filecontents}
\pgfplotsset{width=14cm,compat=1.12}     

\begin{filecontents*}{data.csv}
count  date
38  2015-01-28
5  2015-02-11
21  2015-02-15
1  2015-02-16
21  2015-02-17
21  2015-02-18
62  2015-02-19
16  2015-02-25
4  2015-02-26
1  2015-02-30
1  2015-03-07
44  2015-04-07
\end{filecontents*}

\begin{document}
\begin{tikzpicture}
\pgfplotstableread{data.csv}\data
\begin{axis}[
    ymin = 0,
    x tick label style = {font = \small, text width = 1.7cm, align = center, rotate = 70, anchor = north east},
    xtick=data,
    xticklabels from table = \data{date}
    ]
\addplot [green,mark=*, mark options={blue}] table [x expr=\coordindex, y = count] \data;
\end{axis}
\end{tikzpicture}
\end{document} 
Related Question