假设我们有来自用户的以下情节达斯比斯显示pgfplot
带有时间轴的:
最小工作示例(MWE):
\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot, statistics}
\pgfplotsset{compat=newest}
\usepackage{filecontents}
\begin{filecontents*}{data.txt}
no, date, value
1, 2015-09-13 21:00:00, 922
2, 2015-09-13 22:00:00, 3993
3, 2015-09-13 23:00:00, 3003
4, 2015-09-14 00:00:00, 991
5, 2015-09-14 01:00:00, 2021
6, 2015-09-14 02:00:00, 841
7, 2015-09-14 03:00:00, 2812
8, 2015-09-14 14:00:00, 991
9, 2015-09-14 15:00:00, 231
10, 2015-09-14 16:00:00, 678
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ xlabel=Time,
ylabel=Value,
date coordinates in=x,
table/col sep=comma,
date ZERO=2015-09-13,
xticklabel=\hour:\minute,
xticklabel style={rotate=90, anchor=near xticklabel}, ]
\addplot+[no markers] table[x=date,y=value] {data.txt};
\end{axis}
\end{tikzpicture}
\end{document}
结果截图:
问题说明:
如您所见,x 轴的显示非常奇怪xticks
。
我怎样才能强制pgfplots
仅显示偶数xticks
(例如类似的好时光)等等19:00
,20:00
而不是类似的不愉快的奇数随机时光19:12
?
我知道我可以简单地使用一种方法来仅显示所需xticks
的
xticks = {20:00, 21:00}
和xtick label = {20:00, 21:00}
,
但是 - 如果您的时间跨度较长且包含许多值,这会导致大量工作。我想pgfplots
无论如何都可以强制仅显示偶数时间数字?
答案1
您只需要调整xtick distance
(知道这1
意味着1 day
)。
\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot, statistics}
\pgfplotsset{compat=newest}
\usepackage{filecontents}
\begin{filecontents*}{data.txt}
no, date, value
1, 2015-09-13 21:00:00, 922
2, 2015-09-13 22:00:00, 3993
3, 2015-09-13 23:00:00, 3003
4, 2015-09-14 00:00:00, 991
5, 2015-09-14 01:00:00, 2021
6, 2015-09-14 02:00:00, 841
7, 2015-09-14 03:00:00, 2812
8, 2015-09-14 14:00:00, 991
9, 2015-09-14 15:00:00, 231
10, 2015-09-14 16:00:00, 678
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ xlabel=Time,
ylabel=Value,
date coordinates in=x,
table/col sep=comma,
date ZERO=2015-09-13 00:00:00,
xticklabel=\hour:\minute,
xtick distance=2/24,
xticklabel style={rotate=90, anchor=near xticklabel}, ]
\addplot+[no markers] table[x=date,y=value] {data.txt};
\end{axis}
\end{tikzpicture}
\end{document}