Plotting different columns on the same file using boxes

前端 未结 2 1944
攒了一身酷
攒了一身酷 2021-01-22 05:57

I have a file that looks like

$cat myfile.dat

1 8 32 19230 1.186 3.985
1 8 64 9620 0.600 7.877
1 8 128 4810 0.312 15.136
1 8 256 2410 0.226 20.927
1 8 512 1210         


        
2条回答
  •  太阳男子
    2021-01-22 06:23

    Gnuplot has the smooth option, which can be used e.g. as smooth frequency to sum all y-values for the same x-value. Unfortunately there is no smooth maximum, which you would need here, but one can 'emulate' that with a bit of tricking in the Using statement.

    reset
    xval = -1000
    max(x, y) = (x > y ? x : y)
    maxval = 0
    colnum = 6
    
    set boxwidth 0.2
    
    plot 'mydata.dat' using (val = column(colnum), $1):\
         (maxval_prev = (xval == $1 ? maxval : 0), \
          maxval = (xval == $1 ? max(maxval, val) : val),\
          xval = $1, \
          (maxval > maxval_prev ? maxval-maxval_prev : 0)\
         ) \
         smooth frequency lw 3 with boxes t 'maximum values'
    

    Every using entry can consist of different assignments, which are separated by a comma.

    If a new x value appears, the variables are initialized. This works, because the data is made monotonic in x by smooth frequency.

    If the current value is bigger than the stored maximum value, the difference between the stored maximum value and the current value is added. Potentially, this could result in numerical errors due to repeated adding and subtracting, but judging from you sample data and given the resolution of the plot, this shouldn't be a problem.

    The result for you data is: enter image description here

提交回复
热议问题