arrays - perl:绘制来自多个数组的数据
问题描述
在我的 perl 代码中,我有几个名为 'a'、'b'、'c'.... 'e'、'f' 的数组。我在调用“MyFunc”时将它们作为参数发送。在那里我想绘制任何两个数组,例如,'e' vs 'f'。
我尝试了以下方式(请查看代码),但我收到一条消息,指出my $gd = $graph->plot(\@e,\@f) or die $graph->error;
正在执行命令的行中没有可用的数据点。
如何让它发挥作用?
MyFunc(
'a' => [0, 1,2,3,4],
'c' => [0, -1,2,-3,6],
'c' => [0, 2,4,2,5],
'd' => [0, 1,2,3,4],
'e' => [0, 9,2,1,7],
'f' => [-2, 5,-1,1,7],
'g' => [5, 1,8,-2,5],
);
sub MyFunc {
use GD::Graph::lines;
my $graph = GD::Graph::lines->new;
$graph->set(
x_label => 'X Label',
y_label => 'Y label',
title => 'Some simple graph',
y_max_value => 8,
y_tick_number => 8,
y_label_skip => 2
) or die $graph->error;
my $gd = $graph->plot(\@e,\@f) or die $graph->error;
open(IMG, '>file.gif') or die $!;
binmode IMG;
print IMG $gd->gif;
close IMG;
};
解决方案
将参数传递'e' => [0,9,2,1,7]
给子例程不会自动创建@e
在子例程内调用的变量。您的子例程不会对任何参数进行任何处理。考虑这样的事情来做你想做的事:
sub MyFunc {
my %params = @_;
...
my $gd = $graph->plot( [$params{"e"}, $params{"f"}] ) ...
...
}
推荐阅读
- python - 在python中使用正则表达式从字符串中删除特定模式
- java - [错误]事务生成器。- 当前构建的交易缺少 :classnet/corda/core/contracts/CommandData 的附件
- xaml - 带有 glyp 和标签的按钮
- excel - Check if autofilter range is completely hidden
- sql - 用于替换列中所有 html 标记的 Sql 查询
- python-3.x - 使用 pandas 加载 teradata 表需要花费大量时间
- postgresql - 连接记录集,其中连接值介于另一行中的基值和更高基值之间
- java - Java 模式在 for 循环中绘制
- javascript - 在响应式站点中创建浮动“div”
- python - 从 C# 运行的 Python 脚本使 Python exe 在后台运行,占用内存