微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在多图上方添加空格?

如何解决如何在多图上方添加空格?

我正在使用 gnuplot 的 multiplot 环境。 我很难找到一种方法增加所有图上方的空白,以便为图例腾出一些空间。 我设法通过声明 4,1 的布局但实际上仅使用前三个子图来在图下方添加一个空白区域。 (所以底部是空白的,我可以放 xlabel)。 如果我增加顶部的边距,那么第一个图会被挤压,如图所示。 如何以简单的方式在保持所有子图的高度相同的上方添加这个额外的空白区域。 我把我的简单代码在这里

 


set term pdfcairo size 6,4
set output "currents.pdf"
set xrange [0:1]

set tmargin 0
set bmargin 0
set lmargin 10
set rmargin 2


set multiplot layout 4,1 


############################################# PLOT 1
set tmargin 2

set grid xtics ytics lt 1 lc "grey"

set ytics (-50,-40,-30,-20,-10,10,20,30)

set format x ''

set ylabel "[mV]" offset -3,0

set key at screen 0.8,0.97

plot "ionic_model_0d.csv" using 1:2 title "u" with lines lt 2 lc "red"

set tmargin 0 



################################################# PLOT 2
set key at screen 0.4,0.97

plot "ionic_currents.csv" using "Time":"INaK" with lines 



################################################# PLOT 3
set format x "%1.1f" 

set yrange [-0.002:0.022]

set xtics  (0,0.2,0.4,0.6,0.8,1)

set ytics (0.002,0.006,0.01,0.014,0.018,)

set ylabel "[nA]" offset 0,0

set xlabel "Time [s]"

set grid xtics ytics lt 1 lc "grey"  

set key at screen  0.68,0.97

plot "ionic_currents.csv" using "Time":"Ito" with lines lt 2 lc "blue" 


unset multiplot 

myplots

解决方法

我对您的问题的理解如下:

  • 垂直和水平子图大小相等
  • 子图之间没有空格
  • xtics 仅在底部图表中(不是像 Ethan 的解决方案那样没有 xtics)
  • 可定制的上边距
  • 关键/图例不在子图中,而是在顶部图上方(不是 Ethan 解决方案中没有线条的标签)

我想这就是在 gnuplot 5.0 中引入 multiplot 选项 marginsspacing 的原因。 检查help multiplot。 如果你想在顶部图形上方有按键,你可以将所有按键设置在一个固定的屏幕 y 坐标 myKeyY,但是你必须分配按键并自己设置 x 坐标或定义一个函数来设置x 位置自动。此外,您希望适当地设置 ytics 以避免零间隙图的 ytic 标签重叠。

代码:

### add space on top of multiplot
reset # session

set multiplot layout 3,1 margins 0.12,0.95,0.11,0.87 spacing 0,0 \
            title "Measurements" font ",14" offset 4,0
    myKeyY = 0.93
    
    unset xlabel
    set format x ""
    set ylabel "[mV]"
    set ytics 5
    set grid xtics,ytics
    set key at screen 0.6,myKeyY
    plot x w l lc "red" title "u"

    set ytics 0,20,80
    set key at screen 0.75,myKeyY
    plot x**2 w l lc "web-green" title "INaK"

    set xlabel "Time [s]"
    set xtics
    set key at screen 0.9,myKeyY
    set ylabel "[nA]"
    set ytics -1000,500,500
    set format "%g"
    plot x**3 w l lc "web-blue" title "Ito"

unset multiplot
### end of code

结果:

enter image description here

,
set lmargin screen 0.1
set multiplot layout 4,1 
set multiplot next         # skip the first plot
plot x
plot x**2
set label 1 center at screen 0.5,0.95
set label 1 "Some title that goes above all the plots"
plot x**3
unset multiplot

enter image description here

编辑: 这是一种替代方法。由于标题字体被指定为大(在本例中为 50pt),因此为其保留了额外的空间。但是您可以巧妙地处理实际文本并切换回较小的字体。 或者,您可以使用空格“”作为标题,以便保留该空间,然后通过单独的 set label 命令使用该空间。

set margins 10,10,0
unset xtics

set multiplot layout 4,1 title "Overall title" font ",50" offset 0,-1 right
  plot x
  plot x**2
  set label 1 at screen 0.6,0.95 left "Label line 1\nline 2\nline 3"
  plot x**3
unset multiplot

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。