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:


Here is the code:




\pgfplotstableread[col sep=comma]{../shared/data.csv}\datatable
        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};


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

  • 3
    Pleas add to your question data.csv and minimum code from \documentclass{... to \end{document} Commented Feb 19, 2022 at 21:11
  • 1
    Very good! Thank you! Still missing data.csv (the link only shows a graph) and twp-cfg Commented Feb 19, 2022 at 21:38

1 Answer 1


This example will help you get started.


        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


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


You must log in to answer this question.

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