perl - 我可以在 Chart::Gnuplot(Perl) 中绘制矩阵数据吗?
问题描述
我需要在我的 perl 代码中执行“带有图像的 splot '$map' 矩阵”的 gnulot 脚本,这意味着我需要从仅包含 Z 值的数据生成的热图。我使用 Chart::Gnuplot 但我不知道如何使用它。以下代码可能无法正常工作,我只是将代码放在这里仅供参考。
@map = ([1.01E-6, 0.91E-6, 0.85E-6, ...], [1.13E-6, 1.32E-6, 1.85E-6, ...] .... );
my $chart = Chart::Gnuplot->new(
terminal => "jpeg",
bg => 'white',
pm3d => 'map',
palette => 'defined (0 "green", 2.5E-6 "yellow", 5.0E-6 "red")',
output => $fileName,
title => $pName,
xlabel => 'x',
ylabel => 'y',
);
$chart->set(xrange => $xmin, $xmax);
$chart->set(yrange => $ymin, $ymax);
$chart->set(view => 'map');
my $dataSet = Chart::Gnuplot::DataSet->new(matrix => \@map); # I just tried to check if this works.
# Plot the graph
$chart->plot3d($dataSet);
解决方案
当我在 Chart::Gnuplot::DataSet->new 中使用 using => '1:2:3 with image' 时,gnuplot 绘制了我想要的内容。
my @data = (
[0, 0, 3.06E-6],
[0, 1, 3.13E-6],
[0, 2, 2.99E-6],
[0, 3, 2.98E-6],
[0, 4, 3.12E-6],
[],
[1, 0, 3.11E-6],
[1, 1, 3.21E-6],
[1, 2, 3.00E-6],
[1, 3, 3.12E-6],
[1, 4, 3.23E-6],
[],
[2, 0, 3.32E-6],
[2, 1, 2.97E-6],
[2, 2, 3.00E-6],
[2, 3, 3.30E-6],
[2, 4, 3.12E-6],
[],
[3, 0, 3.05E-6],
[3, 1, 3.33E-6],
[3, 2, 3.32E-6],
[3, 3, 3.19E-6],
[3, 4, 3.20E-6],
[],
[4, 0, 3.21E-6],
[4, 1, 3.23E-6],
[4, 2, 3.22E-6],
[4, 3, 3.00E-6],
[4, 4, 3.11E-6],
);
my $chart = Chart::Gnuplot->new(
terminal => "jpeg",
bg => 'white',
pm3d => 'map',
palette => 'defined (0 "white", 3 "yellow", 5 "red")',
output => "myImage.jpeg",
title => "wafer distribution",
xlabel => 'x',
ylabel => 'y',
xrange => [-1, 5],
yrange => [-1, 5],
);
my $dataSet = Chart::Gnuplot::DataSet->new(
using => '1:2:3 with image',
points => \@data
);
$chart->plot2d($dataSet);
推荐阅读
- angular - Lodash omit not working after angular migration to 6
- ruby-on-rails-5 - 在 Rails 5 中递归渲染部分视图
- java - 覆盖现有适配器
- python - pdblp 中 bdh() 的字段覆盖
- python - 列关闭事件.id 不存在第 1 行:选择“关闭事件”。“id”,“关闭事件”。“所有者”,“关闭
- nginx - 如何使用 Nginx 使用通配符重定向某些路径?
- c++ - 我做错了什么?GetDiskFreeSpaceExA 的功能根本不起作用
- optaplanner - OptaPlanner-如何实现服务功能链(SFC)?
- vba - 用各种标准划界
- android - Android 中的 OpenCV