A
Adam Funk
I'm generating some data points in a Perl program and trying to send
them to gnuplot and get back an "ASCII-art" graph (the kind that
gnuplot generates with the "set term dumb" setting). I'd like to
improve on the following steps:
(1)
foreach $x (sort {$a <=> $b} keys(%table) ) {
$y = $table{$x};
$line = sprintf("%5d %5d\n", $x, $y);
$max_y = $y if ($y > $max_y);
print($line) if ($option{v}); # verbose option
push(@output,$line);
}
This produces lines like this:
-5 2
-2 5
(2) Then I use recipe 7.5 from the Perl Cookbook to generate two temp
files, $data_file and $cmd_file, and I write @output from step (1)
into $data_file.
(3) Then I write a bunch of gnuplot commands as lines to $cmd_file:
set term dumb
set ylabel \"Frequency\"
set xlabel \"Time\"
unset key
set yrange [0:$max_y]
plot \"$temp_filename\" with impulses
(4) and call gnuplot thus:
system('gnuplot', $cmd_file);
The Perl program runs and prints the plot to the screen. I'm about to
modify it to use backticks
$gnuplot_output = `gnuplot $cmd_file`
but I can't believe there isn't a better way than what I've done to
send a list of commands to gnuplot and get the plot back.
Is there?
them to gnuplot and get back an "ASCII-art" graph (the kind that
gnuplot generates with the "set term dumb" setting). I'd like to
improve on the following steps:
(1)
foreach $x (sort {$a <=> $b} keys(%table) ) {
$y = $table{$x};
$line = sprintf("%5d %5d\n", $x, $y);
$max_y = $y if ($y > $max_y);
print($line) if ($option{v}); # verbose option
push(@output,$line);
}
This produces lines like this:
-5 2
-2 5
(2) Then I use recipe 7.5 from the Perl Cookbook to generate two temp
files, $data_file and $cmd_file, and I write @output from step (1)
into $data_file.
(3) Then I write a bunch of gnuplot commands as lines to $cmd_file:
set term dumb
set ylabel \"Frequency\"
set xlabel \"Time\"
unset key
set yrange [0:$max_y]
plot \"$temp_filename\" with impulses
(4) and call gnuplot thus:
system('gnuplot', $cmd_file);
The Perl program runs and prints the plot to the screen. I'm about to
modify it to use backticks
$gnuplot_output = `gnuplot $cmd_file`
but I can't believe there isn't a better way than what I've done to
send a list of commands to gnuplot and get the plot back.
Is there?