[Graph-dev] arbitrary number of data series

Adam Pirkle adam at pirkle.org
Fri Jan 2 10:34:23 PST 2004


[ sent this message privately to Ollie, forgot to post it to the list, so here it is... ]

Fri, Jan 02, 2004 at 03:26:02PM +0000, Ollie Cook said the following:
> Do you perhaps have an example of using arbitrary number of data series, or
> perhaps know where I can look for one?

Here's an example of how I use multiple series. It sounds like you're
wanting to do it the same way. Also, I suspect that in the call to
gnuplot where I pass in @series, you are passing in a reference
instead of the array.

I think that Gnuplot.pm needs some better error messages for input
checking. I can't think of a better interface for it, but the fairly
complex data structure that you have to hand it seems to be pretty
error prone... I screw it up all the time and have to go and start
poking around with the debugger and Data::Dumper to figure out whats
wrong.

my @series;

# Create some random series data
for(0..int rand(5)) {
    my @data = map { [ rand(10),rand(10) ] } (0..20);
    
    push( @series, [ {
                     "title" => "Series $_",
                     "type"  => "matrix"
                    },
                    \@data
                  ] );
}

# Create the plot
gnuplot( {
          "title"        => "Series Plot",
          "x-axis label" => "X",
          "y-axis label" => "Y",
          "output type"  => "png",
          "output file"  => "series.png",
          "extra_opts"   => "set key box 0"
         },
         @series
       ) or die "Gnuplot failed";



Regards,
Adam



More information about the Graph-dev mailing list