2

So i'm really new to pgfplot, a couple of hours now and I'm trying to build a graph such as this:

just a chart

https://www.dropbox.com/s/o3yq97oc9rwmthh/mcgreedy.csv?dl=0 Here is the .csv file!

x-axis is the experiment trial y-axis has 2 different algorithms and the score they yield at each trial

I'm getting some errors that have to do with my attempt of plotting a simple line {x+1} which for now, i'm only trying to do to get a visualisation of what I'm doing

Thanks everyone!

\begin{tikzpicture}
\begin{axis}[
 width=10cm,
  grid = major,
  grid style = {dashed, gray!30},     
  xmin = 0,
  ymin = 0,
  xmax = 105,
  ymax = 280,     
  /pgfplots/xtick = {0,5,...,100},
   axis background/.style = {fill=white},
    ylabel = {Trial Number},
    xlabel = {Score},
    tick align = outside,
   ]   
  \addplot table {mcgreedy.csv}
  %\addplot[domain=0:100, red, thick] ({x+1});
\end{axis}
\end{tikzpicture}
  • Hi, and welcome! What does mcgreedy.csv look like? Which errors do you get? – Torbjørn T. May 16 '16 at 16:43
1

You were just missing a semicolon at the end of the \addplot line`. And by default just one plot is added from a file, so you need two, one for each series.

Some other comments:

  • If you want the legend entries displayed in a row, as in your screenshot, add legend columns=-1.
  • I think there should be some more space between the xticklabels. You can for example reduce the font size a bit (ticklabel style={font=\small}), increase the width of the axis (if there's room), or have fewer ticks. A tick every 10 points may be enough here.
  • Note that you don't need /pgfplots/ before xtick.

\documentclass{article} 
\usepackage{pgfplots,showframe}
\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
  width=0.95\linewidth,
  height=0.6\linewidth,
  grid = major,
  grid style = {dashed, gray!30},     
  xmin = 0,
  ymin = 0,
  xmax = 105,
  ymax = 280,     
  xtick = {0,10,...,100},
  ylabel = {Trial Number},
  xlabel = {Score},
  tick align = outside,
  legend pos=south east,
  legend columns=-1
   ]   
  \addplot table[x index=0,y index=1] {mcgreedy.csv};
  \addplot table[x index=0,y index=2] {mcgreedy.csv};

  \legend{ECTS, E.G.}
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[
  width=0.95\linewidth,
  height=0.6\linewidth,
  grid = major,
  grid style = {dashed, gray!30},     
  xmin = 0,
  ymin = 0,
  xmax = 105,
  ymax = 280,     
  xtick = {0,5,...,100},
  ticklabel style={font=\small},
  ylabel = {Trial Number},
  xlabel = {Score},
  tick align = outside,
  legend pos=south east,
  legend columns=-1
   ]   
  \addplot table[x index=0,y index=1] {mcgreedy.csv};
  \addplot table[x index=0,y index=2] {mcgreedy.csv};

  \legend{ECTS, E.G.}
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}

(The frame shows the text area, generated by the showframe package.) enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.