perl - GD::Graph::直方图无法正常工作

标签 perl graph

我正在尝试使用 GD::Graph::histogram ,根据存储在哈希中的一些数据创建直方图。我的代码如下所示:

sub __gen_pval_histogram {
    my ($tbl_ref, $outfile, $outdir) = @_;
    my $data = [values %$tbl_ref];
    foreach (@$data) {
        $_ = int( -1 * log($_)/log(10) );
    }

    my $hist = new GD::Graph::histogram(400,600);
    $hist->set (x_label      => "p-value",
        y_label      => "count",
        title        => "$outfile",
        x_labels_vertical => 1,
        bar_spacing  => 0,
        shadow_depth => 1,
        shadowclr    => 'dred',
        transparent  => 0,
    ) or warn $hist->error;

    my $out = $hist->plot($data) or die $hist->error;

    open my $file, ">", "$outdir/$outfile" or
        die "Couldn't open $outdir/$outfile: '$?'";
    binmode $file;
    print {$file} $out->png;
    print "Created histogram at $outdir/$outfile\n";
}

my %hash = (a => 0.0000009, b => 0.000034, c => 0.00045, d => 0.0000000012, e => 0.00000098);

__gen_pval_histogram \%hash, "hist.png", ".";

运行此命令会在调用绘图函数时产生错误并生成错误的直方图:

Use of uninitialized value in string eq at /usr/lib/perl5/vendor_perl/5.12.4/GD/Graph/histogram.pm line 42.

显然我将数据传递给函数的方式有问题。我应该怎么做才能解决这个问题?

最佳答案

GD::Graph::Histogram中的第42行引用了参数histogram_type,该参数应该默认为Count,但看起来默认不起作用。

所以尝试包含

histogram_type => 'count',

关于perl - GD::Graph::直方图无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11136380/

相关文章:

java - 寻找最大面积的算法

c++ - spoj 底部的强连接组件

python - 如何在Turtle中制作笑脸?

perl - 我可以在源perl程序中插入断点吗?

web-services - Catalyst:安全下载日志文件

linux - Cron 执行的 Perl 脚本失败

Perl CGI 产生意外的输出

r - 在R?中绘制数据集的CDF?

java - 逆向工程中支配者的重要性

perl - 循环 - 提取记录文本直到下一条记录