#!/usr/bin/perl ########################################### # graph -- Graph of fox/rabbit chase # Mike Schilli, 2004 (m@perlmeister.com) ########################################### use strict; use warnings; use Imager; use Imager::Plot; my $plot = Imager::Plot->new( Width => 550, Height => 350, GlobalFont => '/usr/share/fonts/truetype/tahoma.ttf'); my (@t, @rabbit, @fox); # Generate function data for(my $i = 0.0; $i < 2.0; $i += 0.01) { push @t, $i; push @rabbit, 10 + 5 * $i; push @fox, 7 * $i * $i; } # Add rabbit plot $plot->AddDataSet(X => \@t, Y => \@rabbit, style => { marker => { size => 2, symbol => 'circle', color => Imager::Color->new('green') }}); # Add fox plot $plot->AddDataSet(X => \@t, Y => \@fox, style => { marker => { size => 2, symbol => 'circle', color => Imager::Color->new('red') }}); my $img = Imager->new(xsize => 600, ysize => 400); $img->box(filled => 1, color => 'white'); # Add text $plot->{'Ylabel'} = 'Distance'; $plot->{'Xlabel'} = 'Time'; $plot->{'Title'} = 'Fox vs. Rabbit'; $plot->Render(Image => $img, Xoff => 40, Yoff => 370); $img->write(file => "graph.png");