如何从数据文件gnuplot中的行绘制直方图 [英] How to plot histograms from rows in data file gnuplot

查看:117
本文介绍了如何从数据文件gnuplot中的行绘制直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

t.dat文件如下:

t.dat file looks like this:

              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的数据,依此类推. 到目前为止,我已经设法分别打印出第一组直方图:

The objective is to print 4 series of histograms, each one separated with spaces, one for each group of every 40 lines. So that histogram group 1 plots data from lines 1:40, second group plots the data from lines 41:80, and so on. So far I've managed to print the first group of histograms separately:

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

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

How do I do to plot the other groups in the same plot?

推荐答案

请注意,set style data histograms被忽略,因为用with boxes覆盖了它,并且boxeshistograms是绘制条形的不同方法从分组和整理数据的角度看图表.

Note, that set style data histograms is ignored, because you overwrite it with the with boxes, and boxes and histograms are different ways to plot bar charts from the view point of grouping and arranging the data.

如果可以用

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

然后您可以使用绘制第二组

then you can plot the second group with

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

(using 1,就像您使用的一样,被gnuplot隐式转换为using 0:1). 这两个图将重叠,因为第零列(即当前行数)仅计算应用every过滤器后可用的行,因此在两种情况下x值都从039.要使两者相互绘制,您必须在第二个绘图中添加40(或可能在41之间添加一个小的间距:

(using 1, like you used is implicitely converted to using 0:1 by gnuplot). These two plots would overlap because the zeroth column, i.e. the number of the current row only counts the rows which are available after applying the every filter, so in both cases the x-values go from 0 to 39. To have both plotted beneath each other you must add 40 to the second plot (or maybe 41 to have a small gap between the two:

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

现在,要绘制所有四个组,您可以扩展此plot命令以同时容纳其他两个组,或者使用以下命令对它们进行迭代

Now, to plot all four groups you can either expand this plot command to hold also the other two groups, or you iterate over them with

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

这篇关于如何从数据文件gnuplot中的行绘制直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆