mahmood
mahmood

Reputation: 24705

Using variable colors with points

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

Upvotes: 2

Views: 1063

Answers (1)

Christoph
Christoph

Reputation: 48390

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

Upvotes: 2

Related Questions