gnuplot条形图中的不同颜色的条形图?

Rsa*_*sha 6 gnuplot

我有一个非常简单的数据集:

Critical 2
High 18
Medium 5
Low 14
Run Code Online (Sandbox Code Playgroud)

在此数据集之外的gnuplot中创建条形图很简单,但所有条形图都是相同的颜色.我想拥有它,以便Critical是黑色,高是红色等,但似乎几乎没有任何在线教程这样做.

谁能指出我正确的方向?

mgi*_*son 5

set xrange [-.5:3.5]
set yrange [0:]
set style fill solid
plot "<sed 'G;G' test.dat" i 0 u (column(-2)):2:xtic(1) w boxes ti "Critical" lc rgb "black",\
     "<sed 'G;G' test.dat" i 1 u (column(-2)):2:xtic(1) w boxes ti "High" lc rgb "red" ,\
     "<sed 'G;G' test.dat" i 2 u (column(-2)):2:xtic(1) w boxes ti "Medium" lc rgb "green",\
     "<sed 'G;G' test.dat" i 3 u (column(-2)):2:xtic(1) w boxes ti "Low" lc rgb "blue"
Run Code Online (Sandbox Code Playgroud)

sed会使文件占用三倍空间,以便gnuplot将每一行视为不同的数据集(或"索引").您可以像我一样使用index <number>i <number>简短地分别绘制每个索引.此外,索引号是可用的,column(-2)因为我们如何使盒正确间隔.

可能是一个稍微干净(仅限gnuplot)的解决方案正在使用过滤器:

set xrange [-.5:3.5]
set yrange [0:]
set style fill solid
CRITROW(x,y)=(x eq "Critical") ? y:1/0
HIGHROW(x,y)=(x eq "High") ? y:1/0
MIDROW(x,y) =(x eq "Medium") ? y:1/0
LOWROW(x,y) =(x eq "Low") ? y:1/0
plot 'test.dat' u ($0):(CRITROW(stringcolumn(1),$2)):xtic(1) w boxes lc rgb "black" ti "Critical" ,\
     '' u ($0):(HIGHROW(stringcolumn(1),$2)):xtic(1) w boxes lc rgb "red" ti "High" ,\
     '' u ($0):(MIDROW(stringcolumn(1),$2)):xtic(1) w boxes lc rgb "green" ti "Medium" ,\
     '' u ($0):(LOWROW(stringcolumn(1),$2)):xtic(1) w boxes lc rgb "blue" ti "Low"
Run Code Online (Sandbox Code Playgroud)

这个解决方案也不依赖于数据文件中的任何特定顺序(这就是为什么我更喜欢它与其他解决方案.我们在这里用column(0)(或$0)完成间距,这是数据集中的记录号(在这种情况下,电话号码).