Search code examples
gnuplot

How do you inline a color column with gnuplot?


Considering the accepted answer at Gnuplot: Variable colors (and linewidths) for 2D-Vector plot, why doesn't this work?:

set xrange [0:10]
set yrange [0:10]
plot '-','-','-','-','-' with vectors lw 3 lc rgb variable
1
1
1
1 
e
1
2
3
4
e
2
2
2
2
e
0
0
0
0
e
0x000000
0xff0000
0xff0000
0xffff00
0x382288
e

Error: line 26: Not enough columns for variable color

line 26 is the first color 0x000000


Solution

  • You are probably looking for the following:

    ### inline data
    reset session
    
    set xrange [0:10]
    set yrange [0:10]
    plot '-' u 1:2:3:4:5 with vectors lw 3 lc rgb variable
    1  1  2  0  0x000000
    1  2  2  0  0xff0000
    1  3  2  0  0xff0000
    1  4  2  0  0xffff00
    2  5  2  0  0x382288
    e
    ### end of code
    

    Personally, I would prefer the following way. It has the advantage that you can "re-use" the data in a further plot. Whereas with '-' you would have to enter the data again. Check help special-filenames.

    ### inline data with datablock
    reset session
    
    $Data <<EOD
    1  1  2  0  0x000000
    1  2  2  0  0xff0000
    1  3  2  0  0xff0000
    1  4  2  0  0xffff00
    2  5  2  0  0x382288
    EOD
    
    set xrange [0:10]
    set yrange [0:10]
    plot $Data u 1:2:3:4:5 with vectors lw 3 lc rgb variable
    ### end of code
    

    Result: (for both versions)

    enter image description here