3

I want to add the beginning and end label as extra label to a pgfplot. example as below:

\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}

Two more extra xlabel should be added at the first and last point.

2017-09-27 13:41:49.913 --> 13:41:49.913
2017-09-27 14:15:46.336  --> 14:15:46.336

but actually, only one label added and position is not at the beginning or end.

See output: enter image description here

3

This is caused by your addition of x tick label as interval, which also applies to the extra ticks. You have two ticks, so you get one label in the middle.

Note also that the seconds are always zero, so it doesn't actually matter if you have the seconds-data in the input. 13:41:00 will plot to the same point as 13:41:59.

output of code

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.