8

I have some data as a function of time. I plot it using dateplot from the pgfplots package. I would like to have x labels in hours and minutes. For every day, I would like to have an additional DD.MM.YYYY label. This entry should only appear once per day, so the tick labels don't get too cluttered. (see below for MWE with picture)

Question 1: Is there any way to automatically get an x tick label every three hours? Right now, I have to give a full list with all x tick labels.

Question 2: Can I somehow automate the additional date label?

\documentclass{article}
\usepackage{tikz,pgfplots}
\usepgfplotslibrary{dateplot}
\begin{document}
\begin{tikzpicture}
   \begin{axis}[compat=1.5.1,
        date coordinates in=x,
        xticklabel={\hour:\minute},
        xticklabel style= {rotate=45,anchor=north east},
        xtick={
            {2010-06-22 9:00},
            {2010-06-22 12:00},
            {2010-06-22 15:00},
            {2010-06-22 18:00},
            {2010-06-22 21:00},
            {2010-06-23 00:00},
            {2010-06-23 03:00},
            {2010-06-23 06:00},
            {2010-06-23 09:00}
        },
        date ZERO=2010-06-22,
        xlabel=Date and time,
        xlabel shift=20pt,
        ylabel=Random stuff,
        xmin={2010-06-22 9:00},
        xmax ={2010-06-23 07:25},
        minor x tick num = 2,
        clip=false
        ]
        \addplot coordinates {
            (2010-06-22 09:06:03,0.1)
            (2010-06-22 16:14:07,0.8)
            (2010-06-23 07:00:25,1)
        };
        \node[anchor=north] at (xticklabel cs:0.1) {22.06.2010};
        \node[anchor=north] at (xticklabel cs:0.75) {22.06.2010};
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

0

1 Answer 1

7

This is mainly an answer for question 2: How to automate placement of the day labels:

you can use extra x ticks to simplify the generation of these labels: it would allow you to separate the desired positions from their appearance.

You could do so by adding the lines

    xlabel shift=10pt,
    extra x ticks={2010-06-22 9:00,2010-06-23},
    extra x tick style={
        xticklabel=\day.\month.\year,
        every x tick label/.style={anchor=north west,yshift=-35pt},
    },

Concerning your first question (how can I generate tick positions every 3 hours): there is currently no way to tune the tick label generation in the requested way (the standard way of pgfplots to use 1,2,...,5 does not work for dates as far as I know - at least not for datetime).

3
  • 1
    Thank you, this simplifies the daily markers quite a bit. About the first question: I tried just that (not really thinking it would work). Any plans to include that possibility in future versions? Feb 20, 2012 at 18:20
  • There are currently no plans in this direction. But I can think about it. Feb 20, 2012 at 21:23
  • 2
    +1 for more control over datetime tick generation, I need that too.
    – Tomek
    Feb 26, 2012 at 9:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .