How to plot histograms from rows in data file gnuplot

纵然是瞬间 提交于 2019-12-11 11:57:04

问题


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

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

and print the four groups concatenated:

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?


回答1:


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.

If you can plot the first group with

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

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



来源:https://stackoverflow.com/questions/30442964/how-to-plot-histograms-from-rows-in-data-file-gnuplot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!