我想将开始和结束标签作为额外标签添加到 pgfplot。示例如下:
\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line=middle,
axis y line=middle,
xmajorgrids={false},
xminorgrids={false},
ymajorgrids={true},
yminorgrids={false},
minor tick num=1,
date ZERO=2017-09-27 13:41:49.913,xmin=2017-09-27 13:35:00,xmax=2017-09-27 14:15:55:00,
date coordinates in=x,
xtick distance=0.003472222222222222,% 5min, 5/60/24 = 0.003472222222222222
xticklabel style={
rotate=90,
anchor=near xticklabel,
},
xticklabel=\hour:\minute:\second,
x tick label as interval,
ytick distance=5,
ylabel=\%,
yticklabel={\pgfmathprintnumber{\tick}\%},
extra x ticks={2017-09-27 13:41:49.913,2017-09-27 14:15:46.336},
extra x tick labels={13:41:49,14:15:46},
]
\addplot table [col sep=comma,x=col1,y=col2,mark=] {
col1,col2
2017-09-27 13:41:49.913,9.08
2017-09-27 13:55:16.793,0.63
2017-09-27 14:05:42.076,14.84
2017-09-27 14:15:46.336,0.37
};
\end{axis}
\end{tikzpicture}
\end{document}
应该在第一个点和最后一个点处添加两个额外的 xlabel。
2017-09-27 13:41:49.913 --> 13:41:49.913
2017-09-27 14:15:46.336 --> 14:15:46.336
但实际上,只添加了一个标签,并且位置不在开始或结束。
答案1
这是由于您添加了 造成的x tick label as interval
,这也适用于额外的刻度。您有两个刻度,因此您会在中间得到一个标签。
还要注意,秒数始终为零,因此输入中是否有秒数据实际上并不重要。13:41:00
将绘制到与相同的点13:41:59
。
\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=12cm,height=5cm,
axis x line=middle,
axis y line=middle,
xmajorgrids={false},
xminorgrids={false},
ymajorgrids={true},
yminorgrids={false},
minor tick num=1,
date ZERO=2017-09-27 13:41:49.913,xmin=2017-09-27 13:35:00,xmax=2017-09-27 14:15:55:00,
date coordinates in=x,
xtick distance=0.003472222222222222,% 5min, 5/60/24 = 0.003472222222222222
xticklabel style={
rotate=90,
anchor=near xticklabel,
},
xticklabel=\hour:\minute:\second,
ytick distance=5,
ylabel=\%,
yticklabel={\pgfmathprintnumber{\tick}\%},
extra x ticks={2017-09-27 13:41:49.913,2017-09-27 14:15:46.336},
extra x tick labels={13:41:49,14:15:46},
]
\addplot table [col sep=comma,x=col1,y=col2,mark=] {
col1,col2
2017-09-27 13:41:49.913,9.08
2017-09-27 13:55:16.793,0.63
2017-09-27 14:05:42.076,14.84
2017-09-27 14:15:46.336,0.37
};
\end{axis}
\end{tikzpicture}
\end{document}