PDA

View Full Version : graphing, GD module


naqvia
09-18-2007, 06:38 PM
I am trying to impose to line graphs together that share the same Y-values. I have three arrays and I am making the array to plot like this:
my @values_to_plot = [[@position],[@rep],[@nrep]];

And here is my create gaph object decl. and initialization:
sub create_graph{
my $graph = new GD::Graph::mixed();


$graph->set(
x_label => 'Chr. Positions',
y_label => 'Num. Repeats',
title => 'Chr'.$chr.' Repeats',
bgclr =>'white',
types => [qw(lines lines)],
dclrs => ['green', 'blue'],
transparent =>'0',
x_label_skip=> 100000,
y_label_skip=> 10,
y_tick_number=>10,
) or die $graph->error;

return $graph;

}

However, when the final graph is displayed... it comes out funny with the same graph (x-values) on top of graph and then the same thing on bottom. I plot like this:my $gd = $graph->plot(@plotting_values) or die $graph->error;

## create a png of the graph
open(IMG, ">chr".$chr."_repeats.png") or die $!;
binmode IMG;
print IMG $gd->png;
close IMG;

Why isnt this working?

rwedge
09-19-2007, 09:09 PM
Maybe this gdgraph.com sample62 (http://gdgraph.com/samples/sample62.html) will help. If you want two y labels you will have to set them, or maybe you want to use two axis.

Your x labels are defined in the @position array and the data is the @rep and @nrep arrays. Every arrays should be the same length with any empty values containg 'undef' so they are skipped.