Re: generating time series graphs with perl

From: A. Sinan Unur (1usa_at_llenroc.ude)
Date: 04/30/04


Date: 29 Apr 2004 22:17:46 GMT

Po Boy <a5ufv8u02@sneakemail.com> wrote in
news:pan.2004.04.29.21.46.50.587897@sneakemail.com:

> I'm trying to find a perl module that will help me make a certain kind
> of graph. I believe it's called a time-series graph, but I'm not sure.

...

> I have tried using gnuplot and the GD package for these graphs, but
> have been unable to get either one to generate reasonable looking
> graphs.

You must not have read the documentation.

> Has anyone had success in graphing this kind of data? Can you
> recommend a module or some documentation or pointers that may help me
> out?

Well, you seem to have dismissed the one I would recommend. Use
GD::Graph:

http://search.cpan.org/~mverb/GDGraph-1.43/

> Looking forward to any help you can give me!

The following example can get you started. Please read the docs.

#! perl

use strict;
use warnings;

use GD::Graph::linespoints;

my @data = (
    [ '1998', '1999', '2000', '2001', '2002', '2003', '2004', ],
    [ 3, 5, 6, 3, 1, 2, 5, ],
    [ 5, 1, 2, 2, 3, 2, 7, ],
);

my $graph = GD::Graph::linespoints->new(800, 600);

$graph->set(
    x_label => 'Years',
    y_label => 'Two Variables',
    title => 'Time Series of v1 and v2',
) or die $graph->error;

my $gd = $graph->plot(\@data) or die $graph->error;

open my $png, '>', 'tsplot.png' or die $!;
binmode $png;
print $png $gd->png;

__END__

-- 
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)


Relevant Pages