【问题标题】:Gnuplot: Aligning bars of histogram in multiplotGnuplot:在多图中对齐直方图条
【发布时间】:2020-05-03 10:29:11
【问题描述】:

我正在尝试在多图中绘制 3 个直方图。三个dat文件分别是:

Sta1.dat:

attn,   mu2 ,  mu3, mu4
20,    4.9, 17.1, 78.1 
25,    4.0, 22.0, 74.0 
30,    2.0, 17.0, 81.0 
35,   11.5, 21.7, 66.8 
40,    4.7, 18.0, 77.4 
45,    3.8,  8.9, 87.3 
50,    0.6, 17.3, 82.1 
55,    2.0,  3.4, 94.6 
60,    1.0,  1.3, 97.6 

Sta2.dat

attn,   mu2 ,  mu3, mu4
20,   5.3, 20.6, 74.2
25,   9.2, 27.2, 63.6
30,   9.5, 20.3, 70.2
35,   9.9, 22.1, 68.0
40,   5.3, 19.0, 75.7
45,   3.4,  9.6, 86.9
50,   2.3, 15.3, 82.4
55,   2.7, 10.6, 86.7
60,   1.7,  1.0, 97.3

Sta3.dat

attn,   mu2 ,  mu3, mu4
20,    6.8, 20.6, 72.6
25,    6.2, 29.5, 64.3
30,    5.3, 23.6, 71.1
35,    4.5, 15.6, 79.9
40,    5.5, 17.4, 77.1
45,    3.7, 10.5, 85.8
50,    9.1, 16.6, 74.3
55,    2.8,  3.8, 93.4
60,    1.0,  1.6, 97.4

在 num.jpg 中,直方图的 Station2 和 Station3 条是对齐的,因为显示了图例。在station1中,我没有指定图例,因为直方图的条没有对齐。

有人可以帮助调整命令以对齐所有条形。

set terminal pngcairo
set output "num.png"
set style data histogram
set style histogram rowstacked
set style fill solid
set key outside
set boxwidth 0.5

set size 1,1
set origin 0,0

set datafile separator ","
set multiplot layout 4,1 

set ytics border font ",6" offset 0.7,0
set key title 'Signal Strength' font ",7"
set key font ",5"
set key bottom right
set size 1,0.25
set origin 0,0.50
set lmargin at screen 0.1
set tmargin at screen 0.48
set bmargin at screen 0.27
set rmargin at screen 0.85
set title "Station3" font ",6" offset 0,-0.7
set xtics border font ",6" offset 0,0.7
plot for [COL=2:4] 'sta3.dat' using COL:xtic(1) ti col
unset xtic

set size 1,0.25
set origin 0,0.75
set lmargin at screen 0.1
set tmargin at screen 0.73
set bmargin at screen 0.52
set rmargin at screen 0.85
set xzeroaxis
set title "Station2" font ",6" offset 0,-0.7
plot for [COL=2:4] 'sta2.dat' using COL:xtic(1) ti col
unset key

set size 1,0.25
set origin 0,0.95
set lmargin at screen 0.1
set tmargin at screen 0.96
set bmargin at screen 0.77
set rmargin at screen 0.85
set title "Station1" font ",6" offset 0,-0.7
plot for [COL=2:4] 'sta1.dat' using COL:xtic(1)
unset multiplot
exit

【问题讨论】:

    标签: plot gnuplot histogram


    【解决方案1】:

    我对您的代码进行了一些更改以使用multiplot 命令选项。我删除了单独的 marginsizeorigin 调整,并在终端设置上应用了全局字体大小。奇怪的行为(我不知道如何)来自最后一个plot 命令的ti col

    set terminal pngcairo font ",8"
    set output "num.png"
    set style data histogram
    set style histogram rowstacked
    set style fill solid
    set key outside
    set boxwidth 0.5
    
    set datafile separator ","
    
    set key bottom right Left  # Better alignment to text
    set key title 'Signal Strength' offset -1.5,0
    set xtics nomirror
    set yrange [0:100] # The same yrange to all plots
    
    # layout, direction, 
    # margins and 
    # spacing for plots (see 'help multiplot')
    set multiplot \
        layout 3,1 upwards \
        margins 0.08,0.85,0.08,0.94 \
        spacing 0.1,0.07
    # ----------------------------------------------------
    set title "Station3" offset 0,-0.7
    plot for [COL=2:4] 'sta3.dat' using COL:xtic(1) ti col
    # ----------------------------------------------------
    set xtics tc bgnd # To draw an "invisible" xtics
    set title "Station2"
    plot for [COL=2:4] 'sta2.dat' using COL:xtic(1) ti col
    # ----------------------------------------------------
    unset key
    set title "Station1"
    plot for [COL=2:4] 'sta1.dat' using COL:xtic(1) ti col
    unset multiplot
    exit 
    

    最终结果:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-28
      • 2013-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多