【问题标题】:How to add white space above multiplot?如何在多图上方添加空白?
【发布时间】:2021-04-22 04:00:41
【问题描述】:

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

 


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,0,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 

【问题讨论】:

    标签: matplotlib data-visualization gnuplot data-analysis subplot


    【解决方案1】:

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

    • 垂直和水平子图大小相等
    • 子图之间没有空格
    • xtics 仅在底部图表中(不是 no xtics,如 Ethan 的解决方案)
    • 可自定义的上边距
    • 键/图例不在子图中而是在顶部图上方(不是 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
    

    结果:

    【讨论】:

      【解决方案2】:
      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
      

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

      set margins 10,10,0,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
      

      【讨论】:

      • 谢谢,我不知道“下一个”选项,但我想在图之间的边距为零。也许你知道一个更好的方法来留出一些空白?因为我注意到跳过整个情节会留下太多的空白。
      • 我想这取决于你想放多少文本。 set multiplot 命令本身允许您给出一个放在顶部的标题。我将编辑答案以显示该替代方案。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多