thanks for the answer, I made some additional modification, especially to prevent the the 08 problem.
remove leading zero:
\def\removeleadingzeros#1{\if0#1 \expandafter\else#1\fi}
new definitions: (mostly adding leading 0 to x label and no floating point for seconds)
\def\transformtime#1:#2:#3!{
\pgfkeys{/pgf/fpu=true,/pgf/fpu/output format=fixed}
%\pgfmathparse{#1*3600-\pgfkeysvalueof{/pgfplots/timeplot zero}*3600+#2*60+#3}
\pgfmathparse{\removeleadingzeros#1*3600-\pgfkeysvalueof{/pgfplots/timeplot zero}*3600+\removeleadingzeros#2*60+\removeleadingzeros#3}
\pgfkeys{/pgf/fpu=false}
}
\pgfplotsset{
timeplot zero/.initial=0,
timeplot/.style={
x coord trafo/.code={\expandafter\transformtime##1!},
x coord inv trafo/.code={%
\pgfkeys{/pgf/fpu=true,/pgf/fpu/output format=fixed}
\pgfmathsetmacro\hours{floor(##1/3600)+\pgfkeysvalueof{/pgfplots/timeplot zero}}
\pgfmathsetmacro\minutes{floor((##1-(\hours-\pgfkeysvalueof{/pgfplots/timeplot zero})*3600)/60)}
\pgfmathsetmacro\seconds{##1-floor(##1/60)*60}
\def\pgfmathresult{\pgfmathparse{mod(\hours,60)<10?"0":{},int(mod(\hours,60))}\pgfmathresult:\pgfmathparse{mod(\minutes,60)<10?"0":{},int(mod(\minutes,60))}\pgfmathresult:\pgfmathparse{mod(\seconds,60)<10?"0":{},int(mod(\seconds,60))}\pgfmathresult}
\pgfkeys{/pgf/fpu=false}
},
scaled x ticks=false,
xticklabel=\tick
}
}
Further I removed the floating point for the seconds I did not need. But it should be easy to add.
Example:
\begin{tikzpicture}
\begin{axis}[
timeplot, timeplot zero=0,
xtick={02:08:08,11:30:15}]
\addplot table {
Time State
02:08:00 1
03:54:02 2
04:54:03 3
05:54:04 4
06:54:05 5
07:54:06 6
08:54:07 5
09:54:08 4
10:54:09 3
11:54:10 2
12:54:11 1
};
\end{axis}
\end{tikzpicture}
Cheers
ie to any changes, a horizontal line maintains the new state, rather than an oblique line that connects two points ?
– user21431 Oct 29 '12 at 08:45\addplot +[const plot] .... – Jake Oct 29 '12 at 11:0122is replaced by08(or09) with the error! Package PGF Math Error: Digit '8' invalid for base 8 (in '08*3600-08*3600+54*60+14.75'). As pointed out here, "removing the leading zeros eliminated the error, so it looks like pgfplots thinks that a leading zero means a number in an octal basis, so any digits larger than 7 generates an error". Manually remove these zeros is not always possible. Is there a way to improve this answer in this respect? – Denis Bitouzé Oct 19 '14 at 09:44