2

I need to do a really simple line plot and my data is looking like this:

Date    Value
Apr2013 0.06
Mai2013 0.08
Jun2013 0.1
Jul2013 0.2
Aug2013 0.4
Sep2013 1.5
Okt2013 2.0
Nov2013 4.1
Dez2013 8.1
Jan2014 15.3
Feb2014 23.9
Mär2014 36.5

There is a date in the first column and a float value on the second. The plot should look like that on Apr.2013 the value was 0.06 and so on. So the strings on first column should be on x-axis and the values matching to them on y-axis. I tried it with tikz but I don't know how to handle the dates in the first column. What I've tried was something like this, which of course didn't work:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
        \begin{axis}[width=0.9\textwidth,height=0.9\textheight,
            title={Foo},
            xtick={0,1,2,3,4,5,6,7,8,9,10},
            x tick label style={/pgf/number format/1000 sep=},
            xlabel={Apr},
            y tick label style={/pgf/number format/1000 sep=},
            extra y tick style={grid=major, tick label style={xshift=-1cm}},
            ylabel={GH/s}]
            \addplot table[y=Value] {chart-data.csv};
        \end{axis}
\end{tikzpicture}
\end{document}
0

1 Answer 1

9

Try this:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{width=8cm,compat=1.9}
\usetikzlibrary{pgfplots.dateplot}
\usepackage{pgfplotstable}
\usepackage{filecontents}
\begin{filecontents}{date.dat}
date    value
2013-04-22  0.06
2013-05-22  0.08
2013-06-22  0.1
2013-07-22  0.2
2013-08-22  0.4
2013-09-22  1.5
2013-10-22  2.0
2013-11-22  4.1
2013-12-22  8.1
2014-01-22  15.3
2014-02-22  23.9
2014-03-22  36.5
\end{filecontents}
\begin{document}
%\pgfplotstabletypeset[string type]{date.dat}
\begin{tikzpicture}
\begin{axis}[
date coordinates in=x,
xtick=data,
xticklabel style=
{rotate=90,anchor=near xticklabel},
xticklabel=\month.\year,
title={Foo},
xlabel={Date},
y tick label style={/pgf/number format/1000 sep=},
extra y tick style={grid=major, tick label style={xshift=-1cm}},
ylabel={GH/s},
date ZERO=2009-08-18,% <- improves precision!
]
\addplot table[x=date,y=value] {date.dat};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

The date should be enterd with the day number (any number), because tick labels are set as xticklabel=\month.\year. But I do not know how to change numbers to names of months: 04 to Apr, ans so on.

1
  • 1
    @salenisov : How do I skip some of the Date ticklabels?
    – Abhinav
    May 16, 2018 at 12:40

You must log in to answer this question.