perl:绘制两个单独的数组

时间:2018-10-22 16:44:41

标签: perl plot

我有一个名为@V_list的列表。我创建了另一个与@V_list大小相同的列表,即@nn。现在,我想绘制一个@nn vs @V_list的图。这是我使用的代码,但是在my $gd = $graph->plot(\@nn,\@V_list) or die "Can't plot graph";中出现错误。如何完成?

use GD;      
use GD::Graph::lines;

@V_list=(1,2,1,2);
print "@V_list\n";

$size = @V_list;
@nn=1..$size;
print "@nn\n";


my $graph = new GD::Graph::lines( );
my $gd = $graph->plot(\@nn,\@V_list) or die "Can't plot graph";

open(IMG, '>file.png') or die $!;
binmode IMG;
print IMG $gd->png;
close IMG;

1 个答案:

答案 0 :(得分:2)

GD::Graph::plot方法https://documize.github.io/ad-ldap-test-server/。调用语法应类似于

$graph->plot( [ \@nn, \@V_list ] )

代替

$graph->plot( \@nn, \@V_list )