This is a follow-up question of pgfplot dateplot discrete dates on axis, which is answered by Peter Grill. The solution for plotting discrete dates is to use only unique dates.
However, when making two plots with corresponding dates on the axis, the dates are already known and thus not plotted in the second plot (see figure). Is there a way to forget the "Ticks Used" after the first plot? (I tried to undefine the macro \tick
with: \let\tick=\undefined
, but this doesn't work).
\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{etoolbox}
\usepgfplotslibrary{dateplot}
\pgfplotsset{compat=1.12}
\usepackage{filecontents}
\begin{filecontents*}{data.csv}
date,value
2015-01-01, 3.2
2015-01-02, 6.5
2015-01-04, 6.8
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\centering
\begin{axis}[
date coordinates in=x,
xticklabel={\day-\month-\year},
x tick label style={rotate=45,anchor=north east},
date ZERO=2015-01-01,
grid=both,
enlarge x limits=false,
xlabel={Date (day-month-year)},
ylabel={Value},
xticklabel={%
\ifcsdef{Tick Used \tick}{}{%
\tick%
\csxdef{Tick Used \tick}{}%
}%
},
]
\addplot table [x=date, y=value, col sep=comma] {data.csv};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\centering
\begin{axis}[
date coordinates in=x,
xticklabel={\day-\month-\year},
x tick label style={rotate=45,anchor=north east},
date ZERO=2015-01-01,
grid=both,
enlarge x limits=false,
xlabel={Date (day-month-year)},
ylabel={Value},
xticklabel={%
\ifcsdef{Tick Used \tick}{}{%
\tick%
\csxdef{Tick Used \tick}{}%
}%
},
]
\addplot table [x=date, y=value, col sep=comma] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}
Tick Used \tick Plot 1
andTick Used \tick Plot 2
. Alternatively you would need to keep a list of the\csxdef
and then at the end of the plot clear them.