1

I am trying to make a line graph for annual observations. The X-axis is not displaying the years correctly; they come out as 2,008 / 2,009 etc.

Here is the code I used:

\begin{figure}[h!]
\centering
\begin{tikzpicture}
\begin{axis}[
xlabel=Year,
ylabel=Number of certificates,
legend pos=north east,
legend entries={Eco,Private},
]
  \addplot table [x=Year,y=Eco] {data.txt};
  \addplot table [x=Year,y=Private] {data.txt};
\end{axis}
\end{tikzpicture}
\end{figure}

The table is in a separate file, data.tex, in the following format:

X Year  Private  Eco    
1 2007  5877    nan
2 2008  921253  nan
3 2009  6131    nan
4 2010  6953    nan
5 2011  37184   nan
6 2012  61179   nan
7 2013  374902  18
8 2014  565200  12918
9 2015  137686  227964
10 2016 55295   204323

this is what the output looks like:

graph

How can I get the values on the X axis to display as years?

Emily
  • 11
  • 1
    unrelated but don't use [h!] usually latex will warn and change it (to [!ht]) but [htp] is almost always better. – David Carlisle Aug 03 '18 at 20:54
  • Sorry, most likely I misread your question. Are you asking to get rid of the comma? If so, see here, and perhaps my updated answer. –  Aug 03 '18 at 23:40

1 Answers1

1

Like this. SORRY, most likely I misread your question.

\documentclass[border=3.14mm,tikz]{standalone}
\usepackage{filecontents}
\begin{filecontents*}{data.txt}
X Year  Private  Eco    
1 2007  5877    nan
2 2008  921253  nan
3 2009  6131    nan
4 2010  6953    nan
5 2011  37184   nan
6 2012  61179   nan
7 2013  374902  18
8 2014  565200  12918
9 2015  137686  227964
10 2016 55295   204323
\end{filecontents*}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel=Year,
ylabel=Number of certificates,
legend pos=north east,
legend entries={Eco,Private},
xticklabel style={/pgf/number format/1000 sep={}
}
]
  \addplot table [x=Year,y=Eco] {data.txt};
  \addplot table [x=Year,y=Private] {data.txt};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here