0

so I'm trying to plot a csv file using pgfplots. The csv file looks like this but with more data:

csv file

Here is the download link for the csv: https://datawrapper.dwcdn.net/NDCZf/4/

I tried using the code from this post pgfplot: plot non-numerical data from CSV file . But I end up with something like this:

result

Here is the code:


\documentclass[ngerman]{scrbook}
\usepackage[utf8]{inputenc}

\input{../shared/twp-cfg}

\begin{document}

\pgfplotstableread[col sep=comma]{../shared/data.csv}\datatable \begin{tikzpicture} \begin{axis}[ ybar, xtick=data, xticklabels from table={\datatable}{X}, xticklabel style={rotate=90,anchor=base,yshift=0.82cm}, ] \addplot table [col sep=comma, x expr=\coordindex, y=Terawatt-Hours(TWh)] {../shared/data.csv}; \end{axis} \end{tikzpicture}

\end{document}

Is there a way to fix this and make the plot wider? I'm new to LaTeX, so any help would be welcome. Thanks.

1 Answers1

1

This example will help you get started.

a

\documentclass[12pt,a4paper]{article}

\usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{width=10cm,compat=1.9} \usetikzlibrary{dateplot}

\begin{filecontents}[overwrite]{TRW.dat} date, TRW 2010-11-01, 0.2 2010-12-01, 1 2011-01-01, 2 2011-02-01, 5 2011-03-01, 9 2011-04-01, 15 2011-05-01, 9 2011-06-01, 10 2011-07-01, 10.5 2011-08-01, 14 \end{filecontents}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    date coordinates in=x,
    ybar,
    xtick=data,
    xticklabel style= {rotate=90,anchor=near xticklabel},
    xticklabel=\month --\year,
    title={Energy Consumption},
    xlabel={Date},
    ylabel={Monthly, in terawatt-hours (TWh)},
    ]
    \addplot table[col sep=comma,x=date,y=TRW] {TRW.dat};
\end{axis}

\end{tikzpicture}

\end{document}

Simon Dispa
  • 39,141