The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Gnuplot::Simple - A simple way to control Gnuplot

SYNOPSIS

Gnuplot can be controlled from Perl using a pipe. This modules faciliates the process to allow more convenient graph plotting from perl e.g.

  use Gnuplot::Simple qw(write_data);

  write_data("file.txt", [[ 1,2 ],[ 2,3 ]] );

For obvious reasons, gnuplot needs to be installed for this module to work. The presence of gnuplot is checked using the "which" shell command to verify that it is reachable via $PATH.

FUNCTION/ATTRIBUTES

func write_data($filename, $dataset)

Write the $dataset to the file $filename to create a gnuplot data file. Each element in $dataset should be of the form [[<c1>...<cn>],...]

The column values must not contain newlines (\n or \r) or quote marks. They can be non-ascii unicode.

func exec_commands ($c, $data, $placeholder = "__DATA__")

Example usage:

    use Gnuplot::Simple qw(exec_commands);
    my $d = [ [ 1,2 ],[ 2,3 ] ];
    exec_commands(
        qq{
        set terminal png
        set output "myfile.png"
        plot __DATA__ u 1:2 
        }, $d
    );

The function takes a string of gnuplot commands $c that is piped to gnuplot. You can give a data set as well in the array ref $data. Then, any occurences of __DATA__ in $c are replaced by a temp file containing $data transformed to gnuplot format as done by write_data. The placeholder __DATA__ can be changed via the last parameter.

The function throws the gnuplot error message if execution fails.

LICENSE

This software is licensed under the same terms as Perl itself.