与如何在 gnuplot 中设置标签和线条相同的颜色相关- 但不完全相同...使用此代码:
set style line 1 linetype 1 linewidth 2 pointtype 3 linecolor rgb "aquamarine"
set style line 2 linetype 1 linewidth 2 pointtype 3 linecolor rgb "blue"
set style line 3 linetype 1 linewidth 2 pointtype 3 linecolor rgb "coral"
set xrange [0:3]
set yrange [0:3]
# function to get style index for coloring:
getCol(x) = (x==0)?1:((x==1)?2:3);
plot \
'-' using ($1+0.5):($2+0.5):(getCol($2)) with impulses \
lc variable notitle, \
"" using ($1+0.5):($2+0.5):(stringcolumn(2)):(getCol($2)) with labels \
textcolor variable point linestyle 1 pointtype 7 lc variable \
font ",6" offset character 1.0,character 1.0 notitle
0 0
1 1
1.5 1
2 2
e
0 0
1 1
1.5 1
2 2
e
Run Code Online (Sandbox Code Playgroud)
...我得到这个输出:

看起来对于着色来说一切都很好impulses- 然而对于labels,该方法似乎有效 - 但就好像颜色是从不同的索引读取的?!
那么,如何使用与脉冲线相同的功能使点和标签具有相同的可变颜色?这是在 gnuplot 4.6 补丁级别 1 上...
的颜色索引impulses用于选择线型,而 的labels颜色索引用于选择线型。这种行为在当前的开发版本中仍然存在。根据文档, 的行为labels是正确的。help linecolor variable说:“lc variable告诉程序使用从输入数据的一列读取的值作为线型索引...可以使用tc variable“类似地设置文本颜色。Bug、功能或错误的文档?
作为解决方法,您可以使用lc palette并适当定义palette:
set style line 1 linetype 1 linewidth 2 pointtype 3 linecolor rgb "aquamarine"
set style line 2 linetype 1 linewidth 2 pointtype 3 linecolor rgb "blue"
set style line 3 linetype 1 linewidth 2 pointtype 3 linecolor rgb "coral"
set palette defined (1 "aquamarine", 2 "blue", 3 "coral")
unset colorbox
set xrange [0:3]
set yrange [0:3]
# function to get style index for coloring:
getCol(x) = (x==0)?1:((x==1)?2:3)
unset key
plot \
'-' using ($1+0.5):($2+0.5):(getCol($2)) with impulses lc variable, \
'' using ($1+0.5):($2+0.5):(stringcolumn(2)):(getCol($2)) with labels \
tc palette point ls 1 pt 7 lc palette offset 1,1
0 0
1 1
1.5 1
2 2
e
0 0
1 1
1.5 1
2 2
e
Run Code Online (Sandbox Code Playgroud)
这给出了结果:

我希望该解决方法也适用于您的实际情况。如果由于某种原因无法重新定义调色板,则可以使用lc rgb variable,在这种情况下,最后一列必须是相应 rgb 颜色的整数表示形式:
set style line 1 linetype 1 linewidth 2 pointtype 3 linecolor rgb "aquamarine"
set style line 2 linetype 1 linewidth 2 pointtype 3 linecolor rgb "blue"
set style line 3 linetype 1 linewidth 2 pointtype 3 linecolor rgb "coral"
set xrange [0:3]
set yrange [0:3]
rgb(r,g,b) = 65536 * int(r) + 256 * int(g) + int(b)
rgb1 = rgb(2, 215, 245) # something like aquamarine
rgb2 = rgb(0, 0, 255)
rgb3 = rgb(245,140,2)
getCol(x) = (x==0)?rgb1:((x==1)?rgb2:rgb3)
unset key
plot \
'-' using ($1+0.5):($2+0.5):(getCol($2)) with impulses \
lc rgb variable, \
'' using ($1+0.5):($2+0.5):(stringcolumn(2)):(getCol($2)) with labels \
tc rgb variable point ls 1 pt 7 lc rgb variable offset 1,1
0 0
1 1
1.5 1
2 2
e
0 0
1 1
1.5 1
2 2
e
Run Code Online (Sandbox Code Playgroud)
您可能只需要调整 RGB 值。
不过,我将在 gnuplot 邮件列表上提出这个讨论,看看这是否真的是一个错误,或者其他什么。