pgfplots:如何将星期几的名称添加到 dateplot 中?

pgfplots:如何将星期几的名称添加到 dateplot 中?

假设我们有以下代码:


最小工作示例(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,
                     xmin                = 2019-04-02 12:00:00,
                     xticklabel          = \month-\day,
                     table/col sep       = semicolon]
                     \addplot table[x=Date,y=Value]{data.csv};
        \end{axis}
    \end{tikzpicture}%
\end{document}

结果截图:

结果截图


问题:

  • 我怎样才能numeric datesweekdays names类似星期一星期二星期三。星期四。星期五星期六太阳。
  • 是否有可用的选项可以自动计算每个的pgfplots相应值?names of the days of the weeknumeric date

我想避免xtick labels = {Mon., Tue., Wed., ...}手动设置每一个tick

答案1

看起来您可以使用pgfcalendar包提供的宏将其转换\year-\month-\day为儒略日(\pgfcalendardatetojulian),然后转换为星期几(\pgfcalendarjuliantoweekday),然后打印相应的星期几(\pgfcalendarweekdayshortname),所有操作都直接在xticklabel

xticklabel          = \pgfcalendardatetojulian{\year-\month-\day}{\tmpCnt}\pgfcalendarjuliantoweekday{\tmpCnt}{\tmpCnt}\pgfcalendarweekdayname{\tmpCnt},

\newcnt\tmpCnt是必需的。

我还建议添加,xtick distance=1这样您每天只会获得一个勾号。

\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}
\newcount\tmpCnt
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[date coordinates in = x,
                     xmin                = 2019-04-02 12:00:00,
                     xticklabel          = \pgfcalendardatetojulian{\year-\month-\day}{\tmpCnt}\pgfcalendarjuliantoweekday{\tmpCnt}{\tmpCnt}\pgfcalendarweekdayshortname{\tmpCnt},
                     xtick distance      = 1,
                     table/col sep       = semicolon]
                     \addplot table[x=Date,y=Value]{data.csv};
        \end{axis}
    \end{tikzpicture}%
\end{document}

在此处输入图片描述

相关内容