0

I have a file formatted as follows:

A 12.0 255,20,147
B 325.0 255,255,0
C 134456.0 255,255,0
D 13869.0 0,0,0
E 4321.0 255,0,0
F 43676.0 165,42,42

I would like to produce a histogram where $2 is the height of the bar, $1 is the label (i.e.: it is written below the bar, under the x axis) and $3 is the RGB colour of the bar. I have read this and this but I still can't figure out how to do what I just described.

Community
  • 1
  • 1
Simone Bronzini
  • 1,057
  • 1
  • 12
  • 23

1 Answers1

0

I found a way to do it: you first have to change the formatting of the rgb colours changing the commas to spaces, so that the new file becomes:

A 12.0 255 20 147
B 325.0 255 255 0
C 134456.0 255 255 0
D 13869.0 0 0 0
E 4321.0 255 0 0
F 43676.0 165 42 42

then you have to instruct gnuplot on how to parse the rgb colours:

rgb(r,g,b) = int(r)*65536 + int(g)*256 + int(b)

finally you can specify that you want column 1 to be the label (xticlabels(1)) and that you want variable colour (lc rgb variable), passing your rgb function the appropriate columns of your file (rgb($3,$4,$5)). Summing it all up, the following commands worked for me:

set style fill solid
rgb(r,g,b) = int(r)*65536 + int(g)*256 + int(b)
plot 'hist_test.dat' using (column(0)):2:(0.5):(rgb($3,$4,$5)):xticlabels(1) w boxes lc rgb variable;
Simone Bronzini
  • 1,057
  • 1
  • 12
  • 23