假设我们有以下代码:
最小工作示例(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 dates
用weekdays names
类似星期一,星期二,星期三。,星期四。,星期五,星期六,太阳。? - 是否有可用的选项可以自动计算每个的
pgfplots
相应值?names of the days of the week
numeric 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}