Nik*_*kko 6 gnuplot colors legend
我有一个3列的文件,前两个是位置xy和第三个我用它来定义颜色所以我有这样的东西:
set palette model RGB defined ( 1 'black', 2 'blue', 3 'green', 4 'red')
unset colorbox
plot "file" u 2:1:3 w points pt 14 ps 2 palette, "file2" u 2:1:3 w points pt 14 ps 2 palette
Run Code Online (Sandbox Code Playgroud)
现在的问题是:是否有可能有这种点和颜色的正确传说?由于这些点将具有不同的颜色(根据托盘),我想指定图例中每种颜色的含义.
我想到的唯一解决方案是在图中的某处写一些带有点的字符的文本(在本例中为第14页)并指定颜色......但这不是真正的解决方案吗?
所以请帮忙!
没有选择,你需要摆弄一下.这是YAGH(又一个gnuplot hack);)
假设您的值等距离间隔,您可以使用'+'特殊文件名和labels绘图样式.
要仅显示自定义键,请考虑以下示例:
labels="first second third fourth"
set xrange[0:1] # must be set for '+'
set yrange[0:1]
set samples words(labels) # number of colors to use
key_x = 0.8 # x-value of the points, must be given in units of the x-axis
key_y = 0.8
key_dy = 0.05
set palette model RGB defined ( 1 'black', 2 'blue', 3 'green', 4 'red')
unset colorbox
plot '+' using (key_x):(key_y + $0*key_dy):(word(labels, int($0+1))):0 \
with labels left offset 1,-0.1 point pt 7 palette t ''
Run Code Online (Sandbox Code Playgroud)
这给出了(4.6.4):

由于set samples不影响数据图,您可以直接将其集成到plot命令中:
...
unset key
plot "file" u 2:1:3 w points pt 14 ps 2 palette, \
"file2" u 2:1:3 w points pt 14 ps 2 palette, \
'+' using (key_x):(key_y - $0*key_dy):(word(labels, int($0+1))):0 \
with labels left offset 1,-0.1 point pt 14 ps 2 palette
Run Code Online (Sandbox Code Playgroud)
但是,你需要设置一个适当的xrange,yrange和值key_x,key_y和key_dy.
这不是最直观的方式,但它的工作原理:)