Gnuplot gets iterators

· Read in about 1 min · (192 Words)
gnuplot iterators iteration

Whilst looking at the gnuplot website, I discovered the demo page, which shows, amongst other things, new features in the CVS version.

The main that caught my eye was the plot on the right, which shows a few overlaid sinusoids, with the code used to generate them as the key. Here’s the code:

plot for [n=2:10] sin(x*n)/n with filledcurves

That’s right, one line for 8 plots! Version 4.3 of gnuplot introduces the for keyword, which lets you sweep through numerical parameters and loop through strings. The help (see help iteration with 4.3) has a few examples, which I’ve copied in below:

plot for [filename in "A.dat B.dat C.dat"] filename using 1:2 with lines
plot for [basename in "A B C"] basename.".dat" using 1:2 with lines
set for [i = 1:10] style line i lc rgb "blue"
unset for [tag = 100:200] label tag

I downloaded and compiled the sources and whipped up a quick example of my own (I couldn’t get aquaterm going though). You can see it below:

gnuplot has iterators!
Uploaded with plasq's Skitch!

I’ve got preliminary support going in the Gnuplot TextMate bundle, but I’m still not 100% happy with it yet.

Comments