删除gnuplot多图中的空白间隙 [英] Removing blank gap in gnuplot multiplot
问题描述
我在gnuplot中使用multiplot在单个图形中插入四个图形.我的代码如下:
I am using multiplot in gnuplot to insert four graphs in the single figure. My code looks like this:
set term postscript eps enhanced color
set xlabel 'i'
set ylabel 'j'
set xtics 20
set ytics 20
set xlabel font ",20"
set ylabel font ",20"
set pm3d map
set pm3d corners2color c1
set out "Rulkovpattern.eps"
set multiplot layout 2,2
set title "(a)"
set size square 0.55,0.55
spl 'patternD0pt02.dat' notitle
set title "(b)"
set size square 0.55,0.55
spl 'patternD0pt04.dat' notitle
set size square 0.55,0.55
set title "(c)"
spl 'patternD0pt06.dat' notitle
set size square 0.55,0.55
set title "(d)"
spl 'patternD0pt08.dat' notitle
unset multiplot
set out
set term wxt
这将生成以下图片:
This generates the following picture:
但是在这张照片中,中间有很多空白.我想使该空间消失或至少使其尽可能最小.如何通过修改代码来做到这一点?
But in this picture, there is a lot of blank space in the middle. I would like to make that space disappear or at least make it as minimum as possible. How can I do it by modifying my code?
预先感谢
推荐答案
使用multiplot
正确设置边距有点繁琐,尤其是在使用具有很大边距的set pm3d map
时.
Getting the margins right with multiplot
is a bit tedious, especially when using set pm3d map
, which has quite large margins.
从5.0版本开始,multiplot
具有选项margins
和spacing
.
Since 5.0 version,multiplot
has the options margins
and spacing
.
margins
包含四个数字set multiplot margins <left>,<right>,<bottom>,<top>
,这些数字给出了多图布局周围固定的总边距. spacing
取两个数字set multiplot spacing <xspacing>,<yspacing>
,该数字给出两行(<yspacing>
)或两列(<xspacing>
)之间的距离.
margins
takes four numbers set multiplot margins <left>,<right>,<bottom>,<top>
, which give the fixed overall margins around the multiplot layout. spacing
takes two number set multiplot spacing <xspacing>,<yspacing>
which give the distance between two rows (<yspacing>
) or two columns (<xspacing>
).
set terminal pngcairo size 800,600 background rgb '#bbbbbb'
set output 'foobar.png'
set multiplot layout 2,2 \
margins 0.1,0.98,0.1,0.98 \
spacing 0.08,0.08
set ylabel 'ylabel'
plot x
unset ylabel
plot 2*x
set ylabel 'ylabel'
set xlabel 'xlabel'
plot 3*x
unset ylabel
plot 4*x
unset multiplot
结果(使用5.0rc1):
Result (with 5.0rc1):
要使用gnuplot 4.x实现相同的功能,必须手动进行计算或定义一些函数,如以下示例所示.这应该是通用的.
To achieve the same thing with gnuplot 4.x, you must do the calculations by hand or define some functions, like the following example shows. This should be quite universally usable.
您可以将所有常规内容放入配置文件中,例如multiplot.gp
,其中包含功能
You can put all the general stuff in a configuration file, like multiplot.gp
, which contains the functions
init_margins(left, right, bottom, top, dx, dy, rows, cols) = \
sprintf('left_margin = %f; right_margin = %f; top_margin = %f; bottom_margin = %f; ', left, right, top, bottom) . \
sprintf('col_count = %d; row_count = %d; gap_size_x = %f; gap_size_y = %f', cols, rows, dx, dy)
get_lmargin(col) = (left_margin + (col - 1) * (gap_size_x + ((right_margin - left_margin)-(col_count - 1) * gap_size_x)/col_count))
get_rmargin(col) = (left_margin + (col - 1) * gap_size_x + col * ((right_margin - left_margin)-(col_count - 1) * gap_size_x)/col_count)
get_tmargin(row) = (top_margin - (row - 1) * gap_size_y - (row-1) * ((top_margin - bottom_margin - gap_size_y * row_count) / row_count))
get_bmargin(row) = (top_margin - (row - 1) * gap_size_y - row * ((top_margin - bottom_margin - gap_size_y * row_count) / row_count))
set_margins(col, row) = \
sprintf('set lmargin at screen %f;', get_lmargin(col)) . \
sprintf('set rmargin at screen %f;', get_rmargin(col)) . \
sprintf('set tmargin at screen %f;', get_tmargin(row)) . \
sprintf('set bmargin at screen %f;', get_bmargin(row))
然后是主文件
set terminal pngcairo size 800,600 background rgb '#bbbbbb'
set output 'foobar2.png'
load 'multiplot.gp'
eval(init_margins(0.1, 0.98, 0.1, 0.98, 0.08, 0.08, 2, 2))
set multiplot
eval(set_margins(1,1))
set ylabel 'ylabel'
plot x
eval(set_margins(2,1))
unset ylabel
plot 2*x
eval(set_margins(1,2))
set ylabel 'ylabel'
set xlabel 'xlabel'
plot 3*x
eval(set_margins(2,2))
unset ylabel
plot 4*x
unset multiplot
结果(使用4.6.4):
With the result (using 4.6.4):
这篇关于删除gnuplot多图中的空白间隙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!