perlmeditation
ambrus
<p>
This is just so that I can refer to some example code when I tell people to use gnuplot (instead of for example the popular GD module) to draw plots.
<c>
use strict; use warnings; use 5.010;
use IO::Handle;
use File::Temp "tempfile";
my($T,$N) = tempfile("plot-XXXXXXXX", "UNLINK", 1);
for my $t (100..500)
{ say $T $t*sin($t*0.1), " ", $t*cos($t*0.1); }
close $T;
open my $P, "|-", "gnuplot" or die;
printflush $P qq[
unset key
plot "$N" with lines lw 3
];
<STDIN>;
close $P;
__END__
</c>
<p>
You need gnuplot installed on your computer to run this. Read the gnuplot manual if you want to control the plot, for example change its appeariance, use dates as one coordinate, or export the plot to an image file. Use empty lines to draw discontinuous line segments.
<p>
Update: other posts where I've recommended gnuplot are: [id://694709], [id://685862], [id://668395], [id://636278], [id://838040] (recommended), [id://678306], [id://850402], [id://861806], [id://881960], [id://909356] (recommended).
<p>
Update: see also other posts about gnuplot: [id://290624], [id://925437], [id://946101].
<p>
<b>Update</b> 2011-01-28: added the statement <c>close $T;</c> which fixes a possible bug where the handle $T is not flushed.
<!-- kw: chart, graph -->