4

By default, xticklabel = \month/\year, will be displayed as 04/2019. However, I want to display it as 04/19 instead of 04/2019.


Minimum Working Example (MWE):

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{filecontents}
\usepgfplotslibrary{dateplot}

\begin{filecontents}{data.csv}
    Date;                   Value
    2019-04-01 12:00:00;    1
    2019-04-02 12:00:00;    2
    2019-04-03 12:00:00;    3
    2019-04-04 12:00:00;    4
    2019-04-05 12:00:00;    5
\end{filecontents}

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[date coordinates in = x,
                     xticklabel         = \month/\year,
                     table/col sep      = semicolon]
                     \addplot table[x=Date,y=Value]{data.csv};
        \end{axis}
    \end{tikzpicture}%
\end{document}

Screenshot of the result:

Screenshot of the result


The final question is:

How to do so? Is there some option available to custom format the appearance of \year?

Stefan Pinnow
  • 29,535
Dave
  • 3,758

1 Answers1

6

Not knowing if I should answer this, because the crucial part is based on egreg's answer. Anyway: you can do anything with your \year, because it is nothing more than a string of letters.

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{filecontents}
\usepgfplotslibrary{dateplot}

\begin{filecontents}{data.csv}
    Date;                   Value
    2019-04-01 12:00:00;    1
    2019-04-02 12:00:00;    2
    2019-04-03 12:00:00;    3
    2019-04-04 12:00:00;    4
    2019-04-05 12:00:00;    5
\end{filecontents}

\makeatletter % https://tex.stackexchange.com/a/205193/156344
\newcommand*\short[1]{\expandafter\@gobbletwo\number\numexpr#1\relax}
\makeatother

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[date coordinates in = x,
                     xticklabel         = \month/\short{\year},
                     table/col sep      = semicolon]
                     \addplot table[x=Date,y=Value]{data.csv};
        \end{axis}
    \end{tikzpicture}%
\end{document}

enter image description here