Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How do I make the time label in the following image appear as "10:00" (i.e. 10 o'clock) rather than the unexpected and unwelcome "09:60"?

enter image description here

Here's the code that I am using:

\documentclass{beamer}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot} 


\begin{document} 

\frame{
\begin{tikzpicture}
\begin{axis}[
mark =none,
xmin=2009-08-18 08:30,
xmax=2009-08-18 10:29,
ymin=0, 
ymax=189,
grid=both,
axis x line=bottom,
axis y line=left,
date coordinates in=x,
minor x tick num=5,
minor y tick num=4,
xtick={2009-08-18 09:00,2009-08-18 10:00},
ytick={0,50,100,150},
xticklabel= \hour:\minute,
]
\addplot [thick,blue]coordinates {
(2009-08-18 08:30, 000)
(2009-08-18 09:00, 060)
(2009-08-18 09:20, 060)
(2009-08-18 10:00, 100)
(2009-08-18 10:10, 060)
} node [below] {Train A};

\end{axis}
\end{tikzpicture}
}

\end{document}

Supplementary question:

In the image above, why don't the minor tick lines appear before "09:00" but only after?

share|improve this question
    
If you change the xtick min to 2009-08-18 8:30 the minor tick lines reappear, so this looks like a bug; Similarly, if you make the xtick max to 2009-08-18 10:10 it works again. Odd. –  Alan Munn May 18 '11 at 23:34
add comment

1 Answer 1

up vote 5 down vote accepted

This is a known bug that's fixed in the development version of PGFplots. You can include the bugfix without upgrading the package by defining the patched function in your preamble.

I'm not sure what's going on with the grid lines, you may want to file a bug report about that. You can work around it by using the following settings:

minor x tick num=11,
xtick={2009-08-18 08:00,2009-08-18 10:00},
extra x ticks=2009-08-18 09:00

Here's the complete code:

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot} 

\makeatletter
\def\pgfplotslibdateplot@number@to@julian@and@time#1.#2\julianto#3\hourto#4\minuteto#5{%
    #3=#1
    \pgf@xa=0.#2pt
    \multiply\pgf@xa by24
    \afterassignment\pgfplots@gobble@until@relax
    \c@pgf@countb=\the\pgf@xa\relax
    \edef#4{\the\c@pgf@countb}%
    \advance\pgf@xa by-#4pt
    \multiply\pgf@xa by60
    \afterassignment\pgfplots@gobble@until@relax
    \c@pgf@countb=\the\pgf@xa\relax
    % round minutes (we may lose precision here)
    \advance\pgf@xa by-\the\c@pgf@countb pt
    \ifdim\pgf@xa>0.5pt 
        \advance\c@pgf@countb by1
        \ifnum\c@pgf@countb=60
            \c@pgf@countb=#4 %
            \advance\c@pgf@countb by1
            \edef#4{\the\c@pgf@countb}%
            \c@pgf@countb=0
        \fi
    \fi
    \edef#5{\the\c@pgf@countb}%
}
\makeatother


\begin{document} 

\frame{
\begin{tikzpicture}
\begin{axis}[
mark =none,
date ZERO=2009-08-18 08:30,
xmin=2009-08-18 08:30,
xmax=2009-08-18 10:29,
ymin=0, 
ymax=189,
grid=both,
axis x line=bottom,
axis y line=left,
date coordinates in=x,
minor x tick num=11,
minor y tick num=4,
xtick={2009-08-18 08:00,2009-08-18 10:00},
extra x ticks=2009-08-18 09:00,
ytick={0,50,100,150},
xticklabel= \hour:\minute,
]
\addplot [thick,blue]coordinates {
(2009-08-18 08:30, 000)
(2009-08-18 09:00, 060)
(2009-08-18 09:20, 060)
(2009-08-18 10:00, 100)
(2009-08-18 10:10, 060)
} node [below] {Train A};

\end{axis}
\end{tikzpicture}
}

\end{document}

pgfplots dateplot

share|improve this answer
    
I've said it before and I gladly say it again: I love this list. Thanks guys! –  Harry May 19 '11 at 14:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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