# Abbreviated month names as tick labels in PGFplots

How can I modify the following example from PGFplots package to have the x-axis represent months and labelled as JAN, FEB, MAR etc.?

\begin{tikzpicture}
\begin{axis}[
smooth,
stack plots=y,
area style,
enlarge x limits=false]
{(0,1) (1,1) (2,2) (3,2)}
\closedcycle;
{(0,1) (1,1) (2,2) (3,2)}
\closedcycle;
{(0,1) (1,1) (2,2) (3,2)}
\closedcycle;
\end{axis}
\end{tikzpicture}

-

If you just want the labels to be shown as months (rather than also using the months as coordinates), you can define a list that holds the desired abbreviations and use them in the labels by using xticklabel={\pgfmathparse{<\listmacro>[Mod(\tick,12)]}\pgfmathresult}. The Mod operator makes sure that the list "wraps around".

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\def\monthnames{{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}}
\begin{tikzpicture}
\begin{axis}[
smooth,
stack plots=y,
area style,
enlarge x limits=false,
xtick=data,
xticklabel={\pgfmathparse{\monthnames[Mod(\tick,12)]}\pgfmathresult}]
{(0,1) (1,1) (2,2) (3,2)}
\closedcycle;
{(0,1) (1,1) (2,2) (3,2)}
\closedcycle;
{(0,1) (1,1) (2,2) (3,2)}
\closedcycle;
\end{axis}
\end{tikzpicture}
\end{document}


If you want to use the month names as symbolic coordinates, you can use symbolic x coords={<list>}. The coordinates then have to be provided as (<month>,<value>):

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
smooth,
stack plots=y,
area style,
enlarge x limits=false,
symbolic x coords={Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec},
xtick=data]
{(Jan,1) (Feb,1) (Mar,2) (Apr,2)}
\closedcycle;
{(Jan,1) (Feb,1) (Mar,2) (Apr,2)}
\closedcycle;
{(Jan,1) (Feb,1) (Mar,2) (Apr,2)}
\closedcycle;
\end{axis}
\end{tikzpicture}
\end{document}


And finally, you can use "real" dates using the library \pgfplotslibrary{dateplot}. The x coordinates then have to be in the form YYYY-MM-DD, and you can get quite powerful date formatting options for the tick labels by wrapping them in a pgfcalendar. To use the abbreviated months as labels, you would use xticklabel={\pgfcalendar{tickcal}{\tick}{\tick}{\pgfcalendarshorthand{m}{.}}}, where the . represents abbreviated textual labels. t would be the full month names, - would be a numerical representation without leading zeros, 0 would be a numerical representation with leading zeros. Details can be found in the pgfmanual in section 57.2, Typesetting Calendars

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
smooth,
stack plots=y,
area style,
enlarge x limits=false,
date coordinates in=x,
xtick=data,
xticklabel={\pgfcalendar{tickcal}{\tick}{\tick}{\pgfcalendarshorthand{m}{.}}}]
{(2011-1-1,1) (2011-2-1,1) (2011-3-1,2) (2011-4-1,2)}
\closedcycle;
{(2011-1-1,1) (2011-2-1,1) (2011-3-1,2) (2011-4-1,2)}
\closedcycle;