# pgfplots: put a tick each first day of a month with abbreviated month name

I'm trying to get a plot with xticks with the first day of the month, as in this question and using abbreviated month names, as it is done here. This is what I've tried:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\usepgfplotslibrary{dateplot}
\def\monthnames{{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}}

\begin{document}
\def\dateticks{2016-Jan-01}
\foreach \i in {1,...,11}
{\xdef\dateticks{\dateticks,2016-\pgfmathparse{\monthnames[Mod(\i,12)]}\pgfmathresult-01}}

\begin{tikzpicture}
\begin{axis}[
date coordinates in=x,
xtick/.expanded={\dateticks},
xticklabel=\day/\month,
xticklabel style={rotate=90},
]
\addplot coordinates {(2016-01-23,10) (2016-03-05,20) (2016-09-14,10)};
\end{axis}
\end{tikzpicture}
\end{document}


However, this produces the error: Incomplete \iffalse; all text was ignored after line 11. Not sure what the problem is here because I don't have (at least explicitly) a conditional statement.

Any ideas on how to generate the \dateticks macro with the abbreviated month names? What I would like it the following figure, but with the month names instead of numbers:

Thanks!

Maybe you want something like this?

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\usepgfplotslibrary{dateplot}
\def\monthnames{{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}}
\def\dateticks{2016-Jan-01}
\foreach \i in {1,...,11}
{\pgfmathparse{\monthnames[Mod(\i,12)]}%
\xdef\dateticks{\dateticks,2016-\pgfmathresult-01}}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
date coordinates in=x,
xtick=data,
xticklabels/.expanded=\dateticks,
xticklabel style={rotate=90},
]
\addplot coordinates {(2016-01-23,10) (2016-03-05,20) (2016-09-14,10)};
\end{axis}
\end{tikzpicture}
\end{document}


OLDER ANSWER: If you want to use the month names from your list, you can use

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\usepgfplotslibrary{dateplot}
\def\monthnames{{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
date coordinates in=x,
xticklabel=\pgfmathtruncatemacro\mmonth{\month}%
\pgfmathsetmacro{\mymonth}{\monthnames[Mod(11+\mmonth,12)]}%
\day/\mymonth,
xticklabel style={rotate=90},
]
\addplot coordinates {(2016-01-23,10) (2016-03-05,20) (2016-09-14,10)};
\end{axis}
\end{tikzpicture}
\end{document}


However, the same result can be obtained with xticklabel=\day/\pgfcalendarmonthshortname{\month}.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\usepgfplotslibrary{dateplot}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
date coordinates in=x,
xticklabel=\day/\pgfcalendarmonthshortname{\month},
xticklabel style={rotate=90},
]
\addplot coordinates {(2016-01-23,10) (2016-03-05,20) (2016-09-14,10)};
\end{axis}
\end{tikzpicture}
\end{document}

• Thanks @Schrödinger's cat! Do you know why the error in my code? I had a hard time finding why it wasn't working, any insights would be appreciated. – kmundnic Jun 9 '20 at 3:18
• @kmundnic Yes. There are two issues. First, \pgfmathparse is not expandable, so you would need \foreach \i in {1,...,11} {\pgfmathparse{\monthnames[Mod(\i,12)]}\xdef\dateticks{\dateticks,2016-\pgfmathresult-01}}. Then the error when generating the list disappears. Second, if I am not mistaken, this list is not suitable for xtick/.expanded={\dateticks},. You could use xticklabel/.expanded={\dateticks}, but the result is probably not what you want. – user194703 Jun 9 '20 at 3:24