Search code examples
gnuplotscatter-plot

gnuplot scatter plot, labels with color


i have a file with 4 columns (x value), (y value), (label), (rgb color)

for example

1 43.3 JOHN 034143
2 11.6 BRIAN 987654
3 85.2 JOHN 034143
4 72.7 ALEX 765342
5 4.9 PETER 876897
6 42.7 ALEX 765342

i would like to plot each label on the corresponding position (x,y) with the corresponding color.

for example

have JOHN be printed at coordinate (1, 43.3) with rgb-color 034143
and have BRIAN be printed at coordinate (2, 11.6) with rgb-color 987654
and have JOHN be printed at coordinate (3, 85.2) with rgb-color 034143
and ...

to be sure, i would also like the labels to be printed vertically (rotated 90 deg) :-)

how may i achieve this?

(unfortunately and admittedly, im too dummy to extract/synthesize the exact answer from other similar questions or from the official documentation)


Solution

  • Assuming your color values are decimal numbers (rather than hex):

    $DATA << EOD
    1 43.3 JOHN 034143
    2 11.6 BRIAN 987654
    3 85.2 JOHN 034143
    4 72.7 ALEX 765342
    5 4.9 PETER 876897
    6 42.7 ALEX 765342
    EOD
    set border 3; set tics nomirror
    set xrange [0:*]   
    
    plot $DATA using 1:2:3:4 with labels textcolor rgb variable rotate by 90
    

    enter image description here