Pair Networks


Imager::Plot - Perl extension for generating fancy graphic plots in color.


  use Imager;
  use Imager::Plot;

  $plot = Imager::Plot->new(Width  => 550,
  			  Height => 350,
  			  GlobalFont => 'ImUgly.ttf');

  my @X = 0..100;
  my @Y = map { sin($_/10) } @X;
  my @Z = map { 1+cos($_/10) } @X;

  $plot->AddDataSet(X  => \@X, Y => \@Z);
  $plot->AddDataSet(X  => \@X, Y => \@Y,
    		  style=>{marker=>{size   => 2,
    				   symbol => 'circle',
    				   color  => Imager::Color->new('red'),

  $img = Imager->new(xsize=>600, ysize => 400);
  $img->box(filled=>1, color=>'white');

  $plot->{'Ylabel'} = 'angst';
  $plot->{'Xlabel'} = 'time';
  $plot->{'Title'} = 'Quality time';

  $plot->Render(Image => $img, Xoff => 40, Yoff => 370);
  $img->write(file => "testout.png");


This is a module for generating fancy raster plots in color. There is support for drawing multiple datasets on the same plot, over a background image. It's even possible to do shadows with some thinking.

It's also possible to generate clean plots without any chartjunk at all.

The plot is generated in a few phases. First the initial plot object is generated and contains defaults at that point. Then datasets are added with possible drawing specifications.

Most of the actual work is delegated to Imager::Plot::Axis. See the Imager::Plot::Axis manpage for more information on how to control grid generation, ranges for data (zoom).

For more on the drawing styles for Datasets see the Imager::Plot::DataSet manpage.


Arnar M. Hrafnkelsson,

SEE ALSO Imager, Imager::Plot::Axis, Imager::Plot::DataSet, perl(1).