TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 7 down vote accepted

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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