2

I have a data file with the following format

<color>  <point>

For example, the file looks like

AABBCC   10
0A0B0C   20
1A1B1C   30
...

So the X-axis is the row number and the Y-axis is the second column. There is a similar question here. However, it doesn't fit my need because I don't have three column format. Also, in my file, I have defined the colors, so there is no need to use palette (at least, this is what I think!).

As a result, I don't know how to modify the command.

UPDATE

Running the command as Christoph said, shows only block color. Here is the screen shot

enter image description here

Community
  • 1
  • 1
mahmood
  • 23,197
  • 49
  • 147
  • 242

1 Answers1

2

With the option linecolor rgb variable you can specify an integer number which represents an rgb-tuple. So for your data file you must only convert the hex-values to decimal values.

On Linux you can do this conversion simply with the real function and prepending the string 0x to your data values:

plot 'test.dat' using 0:2:(real('0x'.strcol(1))) linecolor rgb variable pt 7 ps 2

Unfortunately, this doesn't work on Windows, something like print real('0xAABBCC') always returns 0.0.

Here is a gnuplot-only conversion function for hexadecimal rgb-values to integers:

hex = '123456789ABCDEF'
hex_to_int(s) = strstrt(hex, s[1:1])*2**20 + \
                strstrt(hex, s[2:2])*2**16 + \
                strstrt(hex, s[3:3])*2**12 + \
                strstrt(hex, s[4:4])*2**8 + \
                strstrt(hex, s[5:5])*2**4 + \
                strstrt(hex, s[6:6])
plot 'test.txt' using 0:2:(hex_to_int(strcol(1))) linecolor rgb variable pt 7 ps 2
Christoph
  • 47,569
  • 8
  • 87
  • 187
  • Using wxt terminal, I don't see any variable color. Also, I didn't find any option in the `set term wxt` for variable rgb color. – mahmood Sep 10 '14 at 06:01
  • The same is true for `set term post eps enhanced color blacktext size 4,2.7 solid "Times-Roman" 12` – mahmood Sep 10 '14 at 06:07
  • I didn't mean it as terminal option, but as plotting option. That should have been an explanation of the line with the `plot` commmand, which uses the `linecolor rgb variable`. Just run this single line an you'll get the expected result. Another note: the `rgb` is essential, `linecolor rgb variable` and `linecolor variable` are different things. – Christoph Sep 10 '14 at 07:05
  • 1
    Ok, I see. My approach works fine on Linux. Seems like the `real` function behaves differently depending on the underlying C library. I'll add an update which works also on Windows. – Christoph Sep 10 '14 at 08:50