首页 > 解决方案 > Gnuplot multiplot 中的双列图

问题描述

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

无论我将情节放在之后还是之前,但我无法想象它。

谢谢。

标签: gnuplot

解决方案


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

结果:

在此处输入图像描述

添加:

只是为了好玩,也许它对你或其他人有用。只需几行,您就可以轻松地在矩阵中设置布局,其中存储了一些数字$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

结果:

在此处输入图像描述


推荐阅读