Gnuplot: Variable colors (and linewidths) for 2D-Vector plot
I am trying to create a 2D Vector-Plot with variable colors (and line-widths) in gnuplot (version 4.4) . I have looked at the examples for points:
splot "vectors.dat" u 1:2:3:4:(rgb($5,$6,$7)) w points pt 7 pointsize var linecolor rgb variable
where rgb is a function which translates the color to a gnuplot friendly format.
A modification toward vectors seemed straightforward, but开发者_开发知识库 I stumbled over several problems. My example code is (for variable coloring):
splot "vectors.dat" u 1:2:(rgb($5,$6,$7)):3:4:(rgb($5,$6,$7)) with vectors head filled size screen 0.05,15,45 linetype 1 linewidth 2 linecolor rgb variable
I have also tried to put 0 in the third column, since gnuplots notation of a vector is (x,y,z) (dx,dy,dz). Furthermore I have also tried to swap the columns, and used random values. But whatever I do, the arrows remain black.
Is there something obvious I am missing?
Thanks in advance,
Arash
I would put only one color specification, e.g.
set xrange [0:10]
set yrange [0:10]
plot "test.dat" using 1:2:3:4:5 with vectors lw 3 lc rgb variable
where test.dat
contains
1 1 2 0 0x000000
1 2 2 0 0xff0000
1 3 2 0 0xffff00
1 4 2 0 0x382288
The same can be done using the following inline rgb
function
rgb(r,g,b) = int(r)*65536 + int(g)*256 + int(b)
plot "test2.dat" using 1:2:3:4:(rgb($5,$6,$7)) with vectors lw 3 lc rgb variable
where test2.dat
now reads
1 1 2 0 0 0 0
1 2 2 0 255 0 0
1 3 2 0 255 255 0
1 4 2 0 56 34 136
Suppose you want to color your data file by vector magnitude, you can also use the palette
option in combination with cbrange
, e.g. (Gnuplot 4.6 example)
set cbrange [0:1]
set palette rgbformulae 33,13,10
plot "data" using 1:2:3:4:(sqrt($3**2+$4**2)) with vectors linecolor palette z
精彩评论