【问题标题】:How to plot histograms from rows in data file gnuplot如何从数据文件gnuplot中的行绘制直方图
【发布时间】:2015-05-25 17:06:08
【问题描述】:

t.dat 文件如下所示:

              260.37
              260.04
              261.53
              261.32
              260.19
              260.49
              260.43
              260.59
              260.26
              260.68
              260.28
              259.93
              260.82
              259.50
              260.29
              260.52
              260.30
              259.91
              262.24
              260.58
              260.74
              260.22
              261.66
              260.31
              260.99
              259.79
              260.90
              259.88
              260.19
              261.50
              259.32
              260.79
              259.94
              260.35
              260.03
              260.07
              261.86
              261.09
              260.60
              260.15
               75.17
               75.16
               75.33
               75.31
               75.34
               75.04
               75.49
               75.25
               75.27
               75.32
               75.10
               75.75
               75.58
               74.86
               75.19
               75.44
               75.29
               75.31
               75.55
               75.91
               75.39
               75.65
               75.85
               75.67
               75.62
               74.87
               75.64
               75.69
               75.13
               77.76
               75.31
               74.87
               75.75
               75.27
               75.61
               74.84
               75.72
               75.40
               74.96
               75.33
               67.20
               67.26
               68.15
               68.67
               68.88
               67.56
               67.71
               66.87
               68.74
               67.32
               66.92
               69.62
               67.29
               66.87
               68.33
               67.73
               68.66
               68.75
               67.00
               67.22
               66.93
               68.81
               67.29
               67.18
               67.33
               67.91
               70.34
               67.15
               68.37
               69.60
               69.74
               69.62
               67.33
               66.79
               67.90
               67.39
               69.88
               68.48
               68.96
               67.36
               47.82
               47.54
               47.74
               47.95
               47.65
               47.71
               47.64
               47.71
               47.47
               48.19
               47.82
               48.06
               47.88
               48.22
               48.31
               47.58
               47.41
               47.85
               47.71
               47.93
               48.34
               47.95
               48.70
               47.58
               47.86
               47.96
               47.80
               48.00
               47.51
               47.56
               47.50
               47.52
               47.47
               47.76
               47.53
               48.27
               47.26
               47.79
               47.67
               47.57

目标是打印 4 组直方图,每组以空格分隔,每组每 40 行一个。因此,直方图组 1 绘制第 1:40 行的数据,第二组绘制第 41:80 行的数据,依此类推。 到目前为止,我已经设法分别打印了第一组直方图:

set boxwidth 0.9 relative
set style data histograms
set style fill solid 1.0 border -1
set xtics ("1" 20, "4" 60, "8" 100, "16" 140)
plot 't.dat' using 1 with boxes ls 6 axes x1y1

并打印连接的四个组:

plot 't.dat' using 1 every ::0::39 with boxes ls 6 axes x1y1

如何在同一个图中绘制其他组?

【问题讨论】:

  • 我将问题回滚到其原始版本,因为您将更新作为新问题发布。这让这个问题更加清晰。

标签: gnuplot histogram


【解决方案1】:

请注意,set style data histograms 会被忽略,因为您会用with boxes 覆盖它,而从分组和排列数据的角度来看,boxes 和histograms 是绘制条形图的不同方式。

如果你可以用

绘制第一组
plot "t.dat" using 0:1 every ::0::39 with boxes

然后你可以绘制第二组

plot "t.dat" using 0:1 every ::40::79 with boxes

(using 1,就像您使用的一样,被 gnuplot 隐式转换为 using 0:1)。 这两个图会重叠,因为第零列,即当前行的数量只计算应用every 过滤器后可用的行,所以在这两种情况下,x 值都从0 到39。要将两者绘制在彼此下方,您必须将 40 添加到第二个绘图(或者可能是 41 以在两者之间留出小间隙:

plot "t.dat" using 0:1 every ::0::39 with boxes,\
     "" using ($0 + 41):1 every ::40::79 with boxes

现在,要绘制所有四个组,您可以扩展此绘图命令以同时保存其他两个组,或者使用迭代它们

set boxwidth 0.7 relative
set style fill solid 1.0 noborder
set xtics ("1" 19.5, "4" 60.5, "8" 101.5, "16" 142.5)
unset key 
plot for [i=1:4] 't.dat' using ($0+(i-1)*41):1 every ::((i-1)*40)::(i*40-1) with boxes lt i

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-23
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 2013-12-19
    • 1970-01-01
    相关资源
    最近更新 更多