我尝试创建多图 (2x2) 和单图的组合。我不确定我做错了什么,但我不知道该怎么做。我的尝试:
plot sin(x) title "this should be a single plot"
set multiplot layout 2,2 title "Those are the multiplots"
set title "A!"
plot sin(x)
set title "B!"
plot cos(x) not
set title "C!"
tan(x) title "tan"
set title "D"
tan(0.5*x) not
Run Code Online (Sandbox Code Playgroud)
不管我把情节放在后面还是前面,但我无法想象它。
谢谢。
您应该在最后两个函数之前添加一个绘图命令,也许unset multiplot在最后添加一个。这应该有效。或者您希望单图和多图都可见?
plot sin(x) title "this should be a single plot"
set multiplot layout 2,2 title "Those are the multiplots"
set title "A!"
plot sin(x)
set title "B!"
plot cos(x) not
set title "C!"
plot tan(x) title "tan"
set title "D"
plot tan(0.5*x) not
unset multiplot
Run Code Online (Sandbox Code Playgroud)
编辑:(手动设置尺寸、原点和边距)
### Multiplot layout
reset session
set multiplot title "These are five plots"
set ytics 0.5
set margins 5,5,2,8 # l,r,b,t
set size 1,0.5
set origin 0,0.6
set title "top plot"
plot sin(x) title "this should be a single plot"
set size 0.5,0.5
set origin 0,0.3
set title "A!"
plot sin(x)
set origin 0.5,0.3
set title "B!"
plot cos(x)
set origin 0,0
set title "C!"
plot sin(2*x)
set origin 0.5,0
set title "D"
plot cos(2*x)
unset multiplot
### end of code
Run Code Online (Sandbox Code Playgroud)
结果:
添加:
只是为了好玩,也许它对您或其他人有用。只需几行,您就可以轻松地在矩阵中设置布局,并在$Layout. 我希望它是不言自明的。
代码:(编辑:简化)
### easy configurable multiplot layout
reset session
# row column height width
$Layout <<EOD
1 1 1 1
1 2 2 2
1 4 2 1
2 1 1 1
3 1 1 4
EOD
stats $Layout u ($1+$3):($2+$4) nooutput # get max number of rows and columns
MPRows = STATS_max_x - 1
MPCols = STATS_max_y - 1
r(i) = word($Layout[i],1)
c(i) = word($Layout[i],2)
h(i) = word($Layout[i],3)
w(i) = word($Layout[i],4)
MPGridX = 1.0/MPCols
MPGridY = 1.0/MPRows
MPSizeX(i) = MPGridX*w(i)
MPSizeY(i) = MPGridY*h(i)
MPOriginX(i) = MPGridX*(c(i)-1)
MPOriginY(i) = 1-MPGridY*(r(i)+h(i)-1)
SetLayout = 'i=i+1; \
set origin MPOriginX(i), MPOriginY(i); \
set size MPSizeX(i) , MPSizeY(i)'
set multiplot
set linetype 1 lc rgb "red"
i=0
@SetLayout
plot sin(x)
@SetLayout
plot cos(x)
@SetLayout
plot x**3
@SetLayout
plot x**2
@SetLayout
plot sin(x)/x
unset multiplot
### end of code
Run Code Online (Sandbox Code Playgroud)
结果: