RGB颜色名称出现问题

ACR

有什么方法可以使用颜色名称代替其十六进制值或RGB三元组来更改绘图颜色?我需要的是与这篇文章中的第一个答案类似的东西我的输入数据(input.dat)如下:

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
迈吉

lc rgb variable将任何字符串整数转换他们评估的颜色之前,这将不是字符串“红”转变为数量为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

从文件中读取具有颜色名称的箭头

函数colorSet(name, rgb)和colorGet(name)将创建和访问名称形式为color_green,color_red,...的变量。这些变量的值是相应的rgb值。

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章