perl - 我可以在 Chart::Gnuplot (Perl) 中填充绘图吗?

标签 perl plot charts gnuplot

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

plot without padding

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

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

而不是这个:

----------
|  +     +
+        |
|     +  |
----------

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

--------------
|    +     + |
| +          |
|       +    |
--------------

最佳答案

您可以使用offsets :

Offsets provide a mechanism to put an empty boundary around the data inside an autoscaled graph. The offsets only affect the x1 and y1 axes, and only in 2D ‘plot‘ commands.

Syntax:

set offsets <left>, <right>, <top>, <bottom>
unset offsets
show offsets

Each offset may be a constant or an expression. Each defaults to 0. By default, the left and right offsets are given in units of the first x axis, the top and bottom offsets in units of the first y axis. Alternatively, you may specify the offsets as a fraction of the total axis range by using the keyword "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);

(Chart::Gnuplot 没有 offsets 选项,但如果您提供它无法识别的选项,它只会 converts it 到Gnuplot set 语句。)

输出:

plot with offsets

关于perl - 我可以在 Chart::Gnuplot (Perl) 中填充绘图吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29954085/

相关文章:

perl - Perl 中的异常有什么问题?

linux - 确定 TCP 端口是否可用的最佳 perl 方法

perl - 如何在反引号内正确使用perl变量名?

r - 按属性对网络节点进行聚类

reporting-services - SSRS : Can you have the label of a (pie) chart be both the category AND the Percent

javascript - 悬停时如何在chart.js中的特定点添加水平线?

mysql - Perl 和 MySQL 插入 XML 字符串导致错误 2006 "server gone away"

python - Matplotlib 多值条形图定制

python - 使用 Matplotlib 绘制等高线图和线框图

javascript - 删除图表上的刻度线