How to count the number of indices in a Gnuplot input file

前端 未结 1 417
旧时难觅i
旧时难觅i 2020-12-20 03:47

so I want to plot from a data file which has an undetermined number of fields of x and y data (of unknown but constant length). I want to plot them all together on one graph

1条回答
  •  有刺的猬
    2020-12-20 03:51

    If you have gnuplot >= 4.6.0, you can use the stats command:

    #!/usr/bin/env gnuplot
    
    reset
    
    datafile = 'data.dat'
    
    set terminal png size 600,400
    set output 'test.png'
    
    stats datafile
    
    plot for [i=1:STATS_blocks] datafile index (i-1) pt 7 ps 2 title 'record '.i
    

    If your data looks like this (with two blank lines separating the data blocks)

    1 1
    
    
    2 2
    
    
    3 3
    
    
    4 2
    
    
    0 3
    

    That script will make this plot:

    enter image description here

    The same should apply for blocks of data with more than one (x,y) pair.

    0 讨论(0)
提交回复
热议问题