Search code examples
gnuplot

Gnuplot read line style from data file column


I'd like to draw an impulse graph from a text file that looks like this:

II 5 0 0 288.40 1.3033e+14 
II 6 0 0 289.60 1.5621e+14 
II 1 4 0 302.70 3.0084e+13 
II 2 4 0 303.40 4.0230e+13 
II 1 5 1 304.40 3.4089e+13

The plot conceptually should be plot "datafile.dat" using 5:6 w impulses ls $2.

Basically, given a previously defined set of line styles, I'd like to input the line style number from column 2 for every couple of plotted points from column 5 and 6.
Also I'd like to create a text box, for every plotted point, taking strings from the first four columns.

Does somebody know if that's possible?


Solution

  • To use the data from column two as line style use set style increment user and linecolor variable:

    set style increment user
    plot "datafile.dat" using 5:6:2 with impulses lc var
    

    In order to place a label, use the labels plotting style:

    plot "datafile.dat" using 5:6:1 with labels offset 0,1
    

    Putting everything together, you have:

    set style increment user
    set for [i=1:6] style line i lt i
    set yrange [0:*]
    set offsets 0,0,graph 0.1,0
    plot "datafile.dat" using 5:6:2 with impulses lc var, "" using 5:6:1 with labels offset 0,1
    

    The result with 4.6.3 is:

    enter image description here