使用绘制较小日期范围内的数据时,某些日期会多次显示以“填充”横轴。我想知道是否可以只显示离散日期。由于我自动生成图形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}