If I have a table, how can I get the table values and use them as parameters for plotting in pgfplots in gnuplot? In particular, how can multiple curves be plotted with the same functional form from multiple rows?

1 Answer 1


Edit: The first way I did this was with \def commands instead of \pgfmathsetmacro, which does not work.


  1. Load the table using \pgfplotstableread
  2. Get the number of rows using \pgfplotstablegetrowsof, and decrement the number by one.
  3. Within the axis, use \foreach to iterate over each row, up to the max value previously found
  4. Use \pgfplotstablegetelem to retrieve the current row and the correct parameters, setting the variables (\a and \b) with \pgfmathsetmacro
  5. Use the variables in the gnuplot command




a b
1 3
2 2
3 1
4 0
5 0.5
3 2
1 9
2 4


\pgfmathsetmacro\adjrows{\pgfplotsretval -1}


\foreach \rownum in {0,...,\adjrows}

\addplot[raw gnuplot] gnuplot{
  set xrange [0:10];
  set samples 100;
  f(x) = \a*x+\b*x*x;
  plot f(x);


Multiple lines, same functional form

You must log in to answer this question.

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