来自文件的带有 rgb 颜色的 Gnuplot 直方图

Gnuplot histogram with rgb colours from file

我有一个格式如下的文件:

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

我想生成一个直方图,其中 $2 是条形的高度,$1 是标签(即:它写在条形下方,x 轴下方),$3 是条形的 RGB 颜色。 我已阅读 this and this 但我仍然无法弄清楚如何执行我刚刚描述的内容。

我找到了一种方法:您首先必须更改 rgb 颜色的格式,将逗号更改为空格,以便新文件变为:

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

然后你必须指导 gnuplot 如何解析 rgb 颜色:

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

最后,您可以指定要将第 1 列作为标签 (xticlabels(1)) 并指定可变颜色 (lc rgb variable),将 rgb 函数传递给相应的列您的文件 (rgb(,,))。 总而言之,以下命令对我有用:

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(,,)):xticlabels(1) w boxes lc rgb variable;