![pgfplot dateplot 轴上的离散日期](https://linux22.com/image/325938/pgfplot%20dateplot%20%E8%BD%B4%E4%B8%8A%E7%9A%84%E7%A6%BB%E6%95%A3%E6%97%A5%E6%9C%9F.png)
使用绘制较小日期范围内的数据时,某些日期会多次显示以“填充”横轴。我想知道是否可以只显示离散日期。由于我自动生成图形pgfplot
,dateplot
所以我不想手动设置刻度。
这是我的工作示例:
\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\pgfplotsset{compat=1.12}
\usepackage{filecontents}
\begin{filecontents*}{data.csv}
date,value
2015-01-01, 3.2
2015-01-02, 6.5
2015-01-04, 6.8
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\centering
\begin{axis}[
date coordinates in=x,
xticklabel={\day-\month-\year},
x tick label style={rotate=45,anchor=north east},
date ZERO=2015-01-01,
grid=both,
enlarge x limits=false,
xlabel={Date (day-month-year)},
ylabel={Value},
]
\addplot table [x=date, y=value, col sep=comma] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
一种可能性是采用pgfplot 轴上的离散整数定义一个tick
嵌入标签的宏,如果该宏已经定义,则取消勾选:
相关问题:
代码:
\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{etoolbox}
\usepgfplotslibrary{dateplot}
\pgfplotsset{compat=1.12}
\usepackage{filecontents}
\begin{filecontents*}{data.csv}
date,value
2015-01-01, 3.2
2015-01-02, 6.5
2015-01-04, 6.8
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\centering
\begin{axis}[
date coordinates in=x,
xticklabel={\day-\month-\year},
x tick label style={rotate=45,anchor=north east},
date ZERO=2015-01-01,
grid=both,
enlarge x limits=false,
xlabel={Date (day-month-year)},
ylabel={Value},
xticklabel={%
\ifcsdef{Tick Used \tick}{}{%
\tick%
\csxdef{Tick Used \tick}{}%
}%
},
]
\addplot table [x=date, y=value, col sep=comma] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}