Gnuplot多图中的双列图

时间:2019-06-06 12:50:18

标签: gnuplot

我尝试创建多图(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

无论我放置图表的时间是早些还是晚些,但我无法对其进行可视化。

谢谢。

1 个答案:

答案 0 :(得分:2)

您应该在最后两个函数之前添加一个plot命令,并可能在末尾添加一个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

修改 :(尺寸,原点和边距的手动设置)

### 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

结果:

enter image description here

添加:

只是为了好玩,也许对您或其他人有用。只需几行,您便可以轻松地在矩阵中设置布局,并在$Layout中存储一些数字。我希望这是不言自明的。

代码:

### easy configurable multiplot layout
reset session

MPRows = 3
MPCols = 4

# 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

MPGridX(r,c,h,w) = 1.0/MPCols
MPGridY(r,c,h,w) = 1.0/MPRows
MPSizeX(r,c,h,w) = MPGridX(r,c,h,w)*w
MPSizeY(r,c,h,w) = MPGridY(r,c,h,w)*h
MPOriginX(r,c,h,w) = MPGridX(r,c,h,w)*(c-1)
MPOriginY(r,c,h,w) = 1-MPGridY(r,c,h,w)*(r+h-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)
SetLayout = 'set origin MPOriginX(r(i),c(i),h(i),w(i)),MPOriginY(r(i),c(i),h(i),w(i)); \
             set size MPSizeX(r(i),c(i),h(i),w(i)),MPSizeY(r(i),c(i),h(i),w(i))'

set multiplot
    set linetype 1 lc rgb "red"
    i=1
    @SetLayout
    plot sin(x)

    i=2
    @SetLayout
    plot cos(x)

    i=3
    @SetLayout
    plot x**3

    i=4
    @SetLayout
    plot x**2

    i=5
    @SetLayout
    plot sin(x)/x
unset multiplot
### end of code

结果:

enter image description here