如何通过字符串定义颜色名称以在 linecolour lc 中使用,不适用于 gnuplot

How to define colour name by string to use in linecolour lc, not working gnuplot

下面的代码没有产生任何错误,只是输出了一条灰线,

col2="#cd0000"
p x w l lc col2

而这个给出了一条红线,因为它应该

p x w l lc "#cd0000"

这是一个错误吗?

勾选help colorspec。您也可以插入 rgb。这也会给出一条红线。

col2 = "#cd0000"
plot x w l lc rgb col2

来自help colorspec

Syntax:

  ... {linecolor | lc} {"colorname" | <colorspec> | <n>}

where <colorspec> has one of the following forms:

  rgbcolor "colorname"    # e.g. "blue"
  rgbcolor "0xRRGGBB"     # string containing hexadecimal constant
  rgbcolor "0xAARRGGBB"   # string containing hexadecimal constant
  rgbcolor "#RRGGBB"      # string containing hexadecimal in x11 format
  rgbcolor "#AARRGGBB"    # string containing hexadecimal in x11 format
  rgbcolor <integer val>  # integer value representing AARRGGBB
  rgbcolor variable       # integer value is read from input file
  • "#cd0000" 不是有效的颜色名称,例如 "red""green""blue"
  • "#cd0000" 不是有效的颜色规范
  • "#cd0000"是一个字符串,不能解释为数字,那么gnuplot貌似会取0,也就是黑色。