我可以在Chart :: Gnuplot(Perl)中填充一个图吗?

Ben*_*Ben 2 perl charts plot gnuplot

我在Perl中使用Chart :: Gnuplot创建一个图形.当我在绘图区域的最边缘有数据点时,很难看到黑色绘图边框:

没有填充的情节

(你能看到(0,3)和(0,4)边缘的绘图点吗?)

有没有办法用空格填充绘图区域,以便图形边缘的绘图点偏离绘图边界?

而不是这个:

----------
|  +     +
+        |
|     +  |
----------
Run Code Online (Sandbox Code Playgroud)

...我希望它看起来更像这样:

--------------
|    +     + |
| +          |
|       +    |
--------------
Run Code Online (Sandbox Code Playgroud)

Thi*_*Not 5

您可以使用偏移量:

偏移提供了一种机制,可以在自动缩放图形中的数据周围放置空边界.偏移仅影响x1和y1轴,仅在2D'plot'命令中.

句法:

set offsets <left>, <right>, <top>, <bottom>
unset offsets
show offsets
Run Code Online (Sandbox Code Playgroud)

每个偏移可以是常数或表达式.每个默认值为0.默认情况下,左右偏移以第一个x轴为单位给出,顶部和底部偏移以第一个y轴为单位给出.或者,您可以使用关键字"graph"将偏移指定为总轴范围的一部分.

以下内容为每个轴添加了10%的偏移量:

use strict;
use warnings;

use Chart::Gnuplot;

my @x = (0, 0, 1);
my @y = (3, 4, 10);

my $chart = Chart::Gnuplot->new(
    output  => 'gnuplot.png',
    xrange  => [0, 1],
    yrange  => [0, 10],
    offsets => 'graph 0.1, graph 0.1, graph 0.1, graph 0.1'
);

my $dataset = Chart::Gnuplot::DataSet->new(
    xdata => \@x,
    ydata => \@y
);

$chart->plot2d($dataset);
Run Code Online (Sandbox Code Playgroud)

(Chart::Gnuplot没有offsets选项,但是如果你提供一个它无法识别的选项,它只是将它转换为Gnuplot set语句.)

输出:

带补偿的情节