1

Possible Duplicate:
pgfplot: Datafile format for datetime field

The solution to the following problem is probably very straightforward, but I've yet to find the right solution.

I'm trying generate a plot from data consisting of 358 lines looking like this:

2011-12-02 02:00:00, 14.43
2011-12-02 04:00:00, 4.49
2011-12-02 06:00:00, 12.33
2011-12-02 08:00:00, 4.23
2011-12-02 10:00:00, 2.49
2011-12-02 12:00:00, 2.26
2011-12-02 14:00:00, 2.32

I'm using the following code to generate the plot:

\documentclass{article}
\usepackage{tikz,pgfplots}
\usepgfplotslibrary{dateplot}
\pgfplotstableread{/home/user/data/csv/servername.cpud3}
\cputable
\begin{tikzpicture}
\begin{axis}
[
axis background/.style={fill,bottom color=gray!50,top color=white},
grid=major,
grid style={dotted,black},
width=15cm,
height=8cm,
date coordinates in=x,
date ZERO=2011-12-02 02:00:00,
xmin =2011-12-02 02:00:00,
xmax =2011-12-31 20:00:00,
xtick=data,
minor tick num=12,
ymax =100,
ylabel=\%,
xticklabel style={rotate=90, anchor=near xticklabel}
]
\addplot[ycomb] table[ y index = 2 ] from \cputable ;
\end{axis}
\end{tikzpicture}

This produces the following graph:

How do I get the data to be plotted for every second hour instead of days without changing the xticklabels?

Jake's comment below solved my problem.

Working example:

\documentclass{article}
\usepackage{tikz,pgfplots}
\usepgfplotslibrary{dateplot}
\begin{document}
\pgfplotstableread[col sep=comma]{/home/user/data/csv/server.cpud3}
\cputable
\begin{tikzpicture}
\begin{axis}
[
axis background/.style={fill,bottom color=gray!50,top color=white},
grid=major,
grid style={dotted,black},
width=15cm,
height=8cm,
date coordinates in=x,
date ZERO=2011-12-02 02:00:00,
xmin =2011-12-02 02:00:00,
xmax =2011-12-31 20:00:00,
xtick=,
minor tick num=12,
ymax =100,
ylabel=\%,
xticklabel style={rotate=90, anchor=near xticklabel}
]
\addplot[ycomb] table[ y index = 1 ] from \cputable ;
\end{axis}
\end{tikzpicture}
\end{document}
Stefan Pinnow
  • 29,535
  • 1
    Hi Rasmus, welcome to TeX.sx! It's always a good idea to post a minimal working example (MWE), i.e. a full file that can be compiled. In this case, your minimal example could contain the data inline in the \addplot command. I've tried to reproduce your result, but for me, the data is plotted correctly. Note that xtick=data is almost definitely not what you want in this case, since it would generate a tick for every data point. Could you try to create a full minimal example? – Jake Jan 12 '12 at 11:32
  • In your real file, do you use \pgfplotstableread[col sep=comma]...? – Jake Jan 12 '12 at 11:36
  • Jake! Thanks. The missing [col sep=comma] was the issue! Thank you for the assistance. – Rasmus Edgar Jan 12 '12 at 11:41
  • @Jake Is it meaningful to make this an answer, or should we close? – Stefan Kottwitz Jan 12 '12 at 14:15
  • 1
    @StefanKottwitz: I think this can be closed as a duplicate of http://tex.stackexchange.com/a/9734/2552 – Jake Jan 12 '12 at 20:44

0 Answers0