0
votes

Having the following text file

0  0  net0 aaaa bbbb cccc
1  1  net1 zzz
2  2  net2 xxx
3  3  net3 yyy
4  5  net4 ttt 0 0
5  5  net5

I need to plot all points described by the first two columns as x,y coordinates and anchoring the informations reported in the following columns (say 3:6) at each point.These info have to be plot separated by newlines, e.g. the point in (0,0) should report (when mouse over it)

net0
aaaa
bbbb
cccc

The script I'm using is the following but it works only with three columns

set terminal canvas enhanced mousing
set termoption enhanced
set label at 0,0 "Origin"
set title 'mouse over points'
plot 'test.txt' using 1:2:3 with labels hypertext point pt 7 ps var lc rgb "black"

It seems that the datafile modifier using works only with three entries. Any help?

1
You can use some other program to add "..." around the name string. Then your commands will work to get the labels, but not as a column, only as a row. - Jonatan Öström
Alternatively, you can add some different field separator, like commas, and achieve the same result with set datafile separator ',' - Jonatan Öström
I have also tried to add the field separator but I always get the labels as a row and not as column. When the third column is very long the text is not well displayed and not much readable. That's why I was asking for some workaround to get it as column. Do you know any other program which can easily plot that datafile in the way I described ? - John
No I don't, but it must be doable with gnuplot. Maybe using the word() function, the replot command the do for loop, the system('command'), and so on. Or maybe conversly, making a bash script that creates a large gnuplot-readable argument string from the data file and pipe it like echo "hugeString" | gnuplot -p from the script. I am regularly using a similar construct to plot multiple files with varying arguments from the terminal. - Jonatan Öström

1 Answers

0
votes

It is unfortunate that your text is not surrounded by "". Nevertheless, you can handle your issue with gnuplot without any external tool.

You didn't specify whether your data columns are separated by TAB or by space. In the following, I assume that they are separated by single space (code needs to be adapted accordingly if not).

Procedure:

  1. Read the data as full line by setting set datafile separator "\n"
  2. extract the numbers with word()
  3. take the rest of the line as your label text
  4. replace spaces by '\n'

Code:

### Hypertext with columns
reset session

$Data <<EOD
0 0 net0 aaaa bbbb cccc
1 1 net1 zzz
2 2 net2 xxx
3 3 net3 yyy
4 5 net4 ttt 0 0
5 5 net5
EOD

# replace function
# replaces string s1 by string s2 in string s
Replace(s,s1,s2) = (RP_s="", RP_n=1, (sum[RP_i=1:strlen(s)] \
    ((s[RP_n:RP_n+strlen(s1)-1] eq s1 ? (RP_s=RP_s.s2, RP_n=RP_n+strlen(s1)) : \
    (RP_s=RP_s.s[RP_n:RP_n], RP_n=RP_n+1)), 0)), RP_s)

set datafile separator "\n"
GetNumber(n) = real(word(strcol(1),n))
GetText(s) = (s[strstrt(s," ")+1:])[strstrt(s[strstrt(s," ")+1:]," ")+1:]
TextToColumn(s) = Replace(GetText(s),' ','\n')

plot $Data u (GetNumber(1)):(GetNumber(2)):(TextToColumn(strcol(1))) w labels hypertext \
    point pt 7 ps 3 lc rgb "red" notitle
### end of code

Result:

enter image description here