2016-11-28 71 views
1

有什么办法可以使用颜色名称而不是其十六进制值或RGB三重来更改我的情节颜色?我需要的是similar to the first answer in this post。我的输入数据(input.dat)如下:问题与RGB颜色名称

1 1 2 0 magenta 
1 2 2 0 red 
1 3 2 0 green 
1 4 2 0 black 

简单的测试:

set xrange [0:10] 
set yrange [0:10] 
plot "input.dat" using 1:2:3:4:5 with vectors lw 3 lc rgb variable 

回答

0

lc rgb variable将任何字符串整数转换他们评估的颜色之前,这将不将字符串“red”转换为数字0xff0000。所以我们必须定义我们自己的转换函数。

你可以使用这个想法从答案https://stackoverflow.com/a/35729052/7010554。这里是一个可能的实现:

colorSet(name, rgb) = sprintf("color_%s = %d", name, rgb) 
colorGet(name) = value(sprintf("color_%s", name)) 

eval colorSet("magenta", 0xff00ff) 
eval colorSet("red",  0xff0000) 
eval colorSet("green", 0x00ff00) 
eval colorSet("black", 0x000000) 
eval colorSet("dark_yellow", 0xc8c800) 

print colorGet("green") 
print color_green 

set xrange [0:10] 
set yrange [0:10] 
plot "input.dat" using 1:2:3:4:(colorGet(stringcolumn(5))) with vectors lw 3 lc rgb variable 

arrows with color names read from file

colorSet(name, rgb)和`colorGet(名称),将创建函数和变量的访问与形式COLOR_GREEN的名字,COLOR_RED,...这些变量的值相应的rgb值。

您可以随意定义颜色,名称不得包含连字符。 gnuplot内部颜色定义由命令show colors显示。

+0

我并不期望定义自己的转换函数。作为定义的颜色名称,我认为它会更简单。但是谢谢@maij,这解决了我的问题。 – ACR