Search code examples
gnuplot

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


The following code does not produce any error but it just ouptut a grey line,

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

while this one gives a red line as it should

p x w l lc "#cd0000"

Is this a bug?


Solution

  • Check help colorspec. You can also insert rgb. This will also give a red line.

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

    From 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" is not a valid color name, like "red", "green", "blue"
    • "#cd0000" is not a valid colorspec
    • "#cd0000" is a string which cannot be interpreted as a number, then it looks like gnuplot will take 0, which is black.