Quantcast
Channel: Tick labels in pgfplots data time format - TeX - LaTeX Stack Exchange
Viewing all articles
Browse latest Browse all 2

Tick labels in pgfplots data time format

$
0
0

I tried to plot a data set containing seconds and milliseconds with pgfplots.I’ve found a solution for my task here (pgfplots data time format), which I changed a bit. This principally works very well.My code goes here:

\documentclass{article}\usepackage{pgfplots}\pgfplotsset{compat=newest}\usepgfplotslibrary{dateplot}\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}    \pgfkeys{/pgf/fpu=false}}\pgfplotsset{    timeplot zero/.initial=0,    timeplot/.style={        y coord trafo/.code={\expandafter\transformtime##1!},        y 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{\pgfmathprintnumber{\hours}:\pgfmathprintnumber{\minutes}:\pgfmathprintnumber[fixed zerofill]{\seconds}}            \pgfkeys{/pgf/fpu=false}        },    scaled y ticks=false,    yticklabel=\tick    }}\begin{document}\begin{tikzpicture}\begin{axis}[    timeplot, timeplot zero=0, grid=major, grid style=dashed, ytick={00:12:00, 00:13:00, 00:14:00},]\addplot table {State           Time  -13 00:12:42.40-12 00:12:57.06-11 00:13:17.59-10 00:13:40.83-9  00:14:07.44-8  00:14:31.11-7  00:14:04.28-6  00:14:12.07-5  00:14:09.27-4  00:13:59.92-3  00:13:56.82-2  00:13:55.17-1  00:13:53.520   00:13:52.471   00:13:59.322   00:14:00.583   00:13:43.124   00:13:49.055   00:13:28.63};\end{axis}\end{tikzpicture}\end{document}

The problem now is that I get odd tick labels (both 12:60 and 14:0.00 is not I was expecting...):

enter image description here

I found a similar question (Date plot using pgfplots with odd tick label), but with that solution I unfortunately do not know how to solve my problem. Could anyone here give me a hint?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images