0

I use this code

\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot table [x=a, y=c, col sep=comma] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}

to plot my data

\begin{filecontents*}{data.csv}
year,count
2016,998
2015,1000
2014,900
2013,837
2012,826
2011,784
2010,801
2009,731
2008,703
2007,632
2006,629
2005,516
2004,512
2003,476
2002,444
2001,497
2000,478
1999,400
1998,393
1997,399
1996,387
\end{filecontents*}

First issue conserns the number on the x and y axis is comma separated value, how to fix it, second issue is about axis labeling, how to put the lables? enter image description here

Mensch
  • 65,388
Artem
  • 1
  • Hi, welcome. For the first, see https://tex.stackexchange.com/questions/31276 or https://tex.stackexchange.com/questions/28607. For the second, \begin{axis}[xlabel=foo,ylabel=bar]. – Torbjørn T. Sep 15 '17 at 22:17

1 Answers1

1

Here is a working example. Find some knowledge in the manual with the corresponding gallery or around here.

This line \pgfkeys{/pgf/number format/.cd,1000 sep={\,}} lets you adjust the separator (sep option).

The label can be set here \begin{axis}[ xlabel=Count, ylabel=Year].

\documentclass{scrartcl}
\usepackage{tikz,pgfplots}
\usepackage{filecontents}
\begin{document}
\pgfkeys{/pgf/number format/.cd,1000 sep={\,}}
\begin{tikzpicture}
\begin{axis}[ xlabel=Count, ylabel=Year]


\addplot[color=blue,mark=*] table[x=year, y=count, col sep=comma]{data.csv};

 \end{axis} 
 \end{tikzpicture}
\end{document}

this needs to go before the picture line, but for a shorter example I stuck this here:

\begin{filecontents}{data.csv}
year,count
2016,998
2015,1000
2014,900
2013,837
2012,826
2011,784
2010,801
2009,731
2008,703
2007,632
2006,629
2005,516
2004,512
2003,476
2002,444
2001,497
2000,478
1999,400
1998,393
1997,399
1996,387
\end{filecontents}
nhck
  • 740
  • 1
    In general, don't use the minimal class, article is a better choice: https://tex.stackexchange.com/questions/42114/why-should-the-minimal-class-be-avoided (And pgfplots loads tikz, so you don't need to explicitly load the latter, strictly speaking.) – Torbjørn T. Sep 15 '17 at 22:23