'Gnuplot labels in column with different shape

I have a little problem. I try create gnu plot with many lines or shapes but header is in last column . Example data in file

18:40:03    0.00 K/s    3.65 K/s  0.00 %  0.25 % AA
18:40:03    0.00 K/s   69.44 K/s  0.00 %  0.05 % BB 
18:40:03     0.40 K/s    0.00 K/s  0.00 %  0.03 % AA

my gnuplot code

set xlabel "Date\nTime"
set timefmt "%H:%M:%S"
set format x "%H:%M:%S"
set xdata time
set autoscale  xy
set term png
set output "io.png"
plot 'io.log' using 0:8 title 'title', \
     '' using 0:8:10 with labels offset 0,char 1
~

But I want create plot where this same type (AA) have this same color or shape and different from BB CC .....

in Problem is this same label



Solution 1:[1]

In order to simplify things, let's assume that the input data is stored in a file test.dat and it has following form:

1   2   AA
2   4   BB
3   6   AA

Then there are several possibilities to distinguish the style based on the value of the label in the third column.

One could for example invoke external processing to filter out records of the "special type" (label "AA" in your case) and specify a particular style:

unset key
set xr [0:4]
set yr [0:10]

plot \
    '< gawk ''$3=="AA"'' test.dat' using 1:2 w p pt 1, \
    '' u 1:2:3 w labels offset 0,char 1 tc rgb 'red', \
    '< gawk ''$3!="AA"'' test.dat' using 1:2 w p pt 2, \
    '' u 1:2:3 w labels offset 0,char 1 tc rgb 'blue'

This produces: enter image description here

Alternatively, in order to distinguish just the style of the labels, one could filter individual cases directly in Gnuplot as:

set terminal png enhanced
set output 'fig2.png'

unset key
set xr [0:4]
set yr [0:10]

checkLabel(label)=(label eq 'AA')
filter(label, val, flag)=(((flag && checkLabel(label))||(!flag && !checkLabel(label)))?val:1/0)

plot \
    'test.dat' using 1:2 w p , \
    '' using 1:(filter(stringcolumn(3), $2, 1)):3 w labels offset 0,char 1 tc rgb 'red', \
    '' using 1:(filter(stringcolumn(3), $2, 0)):3 w labels offset 0,char 1 tc rgb 'blue'

which yields: enter image description here

Solution 2:[2]

A rather old question with no feedback of the OP, but maybe still of interest to others. As I understand, you are basically looking for a lookup table with string input. You can define your keys, pointtypes, colors in strings and "mis-use" the function sum to define a lookup function. Check help sum, help word, help variable.

Script:

### lookup tables with string input for different point types and colors
reset session

$Data <<EOD
1   9    AA
2   8    BB
3   6    CC
4   8    AA
5   6    BB
6   4    DD
7   2    CC
8   4    AA
EOD

myLabels = "AA BB CC DD"
myPts    = "5  7  9  11"     # pointtypes
myColors = "0xff0000 0x00ff00 0x0000ff 0xff00ff"

myPt(col)    = int(word(myPts,Lookup(strcol(col))))
myColor(col) = int(word(myColors,int(Lookup(strcol(col)))))
Lookup(s)    = int(sum [_i=1:words(myLabels)] (word(myLabels,_i) eq s ? _i : 0))

set key noautotitle
set grid x,y
set offset 0.5,0.5,0.5,0.5

plot $Data u 1:2:3:(myColor(3)) w labels tc rgb var font ",12" offset 0,1, \
        '' u 1:2:(myPt(3)):(myColor(3)) w p ps 2 pt var lc rgb var
### end of script

Result:

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ewcz
Solution 2