4

I am plotting a set of graphs using pgfplots and I am loading the data from a csv file. The csv file contains the results of a test which has been executed 10 times, and a column showing the average. I have ploted a graph using one column as the x-axis and another as the y-axis using the following code:

\addplot[
    color=blue,
    only marks,
    mark=+,
    mark size=2.9pt]
table[x={xColumn},y={AvgColumn}]
{file.csv};

but what I need to do is plot all 10 columns, I could achieve this by repeating the code above for 10 times each time using a different column name in y={...}, however this is going to make the document a nightmare to deal with as I have multiple graphs, and in some cases I have to plot more then one set of results on the same axis. I tried to use y={column1,column2,...}, but this does not work. Is there some way of doing something of this sort, or perhaps, a way to set all the settings once then reuse them for 10 times (thus having to write only one line per column)?

Thanks

Torbjørn T.
  • 206,688
Falo
  • 63

1 Answers1

5

You don't have to plot the 10 columns each in a separate figure, PGFPLOTS can handle more than one \addplot on the same two axes. Here is how you can do it:

\begin{tikzpicture}
\begin{axis}[<axis specifications>]
\addplot[
    color=blue,
    only marks,
    mark=+,
    mark size=2.9pt]
table[x={xColumn},y={AvgColumn}]
{file.csv};

\foreach \column in {1,...,10}{
  \addplot+[] table[x={xColumn},y={column\column}] {file.csv};
}
\end{axis}
\end{tikzpicture}
percusse
  • 157,807
AboAmmar
  • 46,352
  • 4
  • 58
  • 127