gnuplot:添加额外的键

gnuplot: add extra keys

我有一个简单的 gnuplot 脚本来绘制具有不同颜色条的直方图,每种颜色代表一个组。

如何显示 3 个不同的键(1 个红色、1 个绿色和 1 个蓝色)?

这是我的脚本:

unset title 
set key left
set yrange [0:10]
set ylabel 'Score'
set xtics rotate out
set style histogram gap 1
set style data histogram
set style fill solid 1.00 border 0
set linetype 1 lc rgb 'red'
set linetype 2 lc rgb 'red'
set linetype 3 lc rgb 'red'
set linetype 4 lc rgb 'green'
set linetype 5 lc rgb 'green' 
set linetype 6 lc rgb 'green'
set linetype 7 lc rgb 'blue'
set linetype 8 lc rgb 'blue'
set linetype 9 lc rgb 'blue'
set xtics nomirror 
set ytics nomirror
plot 'example.dat' using ([=10=]):2:([=10=]+1):xtic(1) with boxes linecolor variable notitle

这是我的 example.dat 文件:

A 1
B 2
C 3
D 4
E 5
F 6
G 7
H 8
I 9

我没有 10 个代表指向 post imgs,所以这些是 imgur 链接: what I get and what I want

提前致谢

忘记手动定义所有这些样式,而是在循环中工作:

unset title 
set key left
set yrange [0:10]
set ylabel 'Score'
set xtics rotate out
set style histogram gap 1
set style data histogram
set style fill solid 1.00 border 0
set xtics nomirror 
set ytics nomirror
plot for [i=1:3] 'example.dat' \
every ::((i-1)*3)::((i-1)*3+2) using ([=10=]+i*3):2:xtic(1) \
with boxes linecolor i title "Gpr".i

上面的代码从 1 循环到 3,每次绘制其中一组。 every 选择要绘制的点,标题作为字符串连接获得。线条颜色简单地选择为 i 从 1 到 3,但您可以使用复杂的条件表达式:

f(x)=(x == 1 ? "magenta" : x == 2 ? "yellow" : "cyan")
plot for [i=1:3] 'example.dat' \
every ::((i-1)*3)::((i-1)*3+2) using ([=11=]+i*3):2:xtic(1) \
with boxes linecolor rgb f(i) title "Gpr".i