Using PLplot from Perl

The PLplot Plotting Library: Programmer's Reference Manual
Prev |  | Next

# Chapter 14. Using PLplot from Perl

There are no proper bindings for the Perl language delivered with the PLplot sources. However, a PLplot interface has been added to the Perl Data Language (PDL) since version 2.4.0. If the PLplot library is installed in the system, it is automatically detected by the PDL configuration script, such that PLplot support for PDL should work out of the box. For further informations see the PDL homepage. Here is an usage example:

    use PDL;
    use PDL::Graphics::PLplot;

    $x = pdl (0..5);
    $y = $x ** 2;

    plsdev ("xwin");
    plinit ();
    plcol0 (1);

    plenv (-0.5, 5.5, -1, 26, 0, 0);
    plline ($x, $y);

    plend ();

There is also a Perl PLplot interface on CPAN which is not dependent on PDL. The Perl module is called Graphics::PLplot and is appropriate for small data arrays. The API is very similar to the C API except that if the number of elements in an array is required by the C function the perl interface calculates it automatically. Also, return values are returned and not supplied as arguments. Here is the PDL example above translated to Graphics::PLplot:

    use Graphics::PLplot qw/ :all /;

    @x = (0..5);
    @y = map {$_ * $_} @x;

    plsdev ("xwin");
    plinit ();
    plcol0 (1);

    plenv (-0.5, 5.5, -1, 26, 0, 0);
    plline (\@x, \@y);

    plend ();

Prev | Home | Next
Embedding Plots in Graphical User Interfaces | Up | Using PLplot from Python