2

I want to design xticklabels as two line texts:

  • First line: Date, e.g. \month/\day
  • Second line: Time, e.g. \hour:\minute

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/\day,
                     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


Screenshot of the desired state:

Screenshot of the desired state


The final question is: How to do so?

It seems that

  • xticklabel = \month/\day \\ \hour:\minute

as well as

  • xticklabel = \month/\day \newline \hour:\minute

does not work.

0
5

The labels are TikZ nodes, so if you want it to be multiline, you must set option allowing it to do so.

\documentclass[margin=1]{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/\day\\xyzt,
                     xticklabel style   = {align=center},
                     table/col sep      = semicolon]
                     \addplot table[x=Date,y=Value]{data.csv};
        \end{axis}
    \end{tikzpicture}%
\end{document}

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.