gnuplot data file with open or close parenthesis / parentheses "(" or ")" : "Skipping" warning / "x range is invalid"

Question:

I would like to read output from a python script that has parentheses and also commas (see below) directly into gnuplot. The error message is given below. Although it works, I would like to avoid pre-processing the output with the usual GNU/Linux tools (sed,awk etc.).

The output is from a python script (obtained on SO, link provided if needed) that is modified to make less editing. One example full line of the output is given below :

QuadraticBezier (106.774, 78.855)

There is a longer .dat file with similar lines that will plot nicely in gnuplot with this command (also obtained on SO – ask for link if needed):

plot "input.dat" using ($3):($2):2 w l, "input.dat" u 3:2

the gnuplot error message includes a ^ :

         warning: Skipping data file with no valid points
         warning: Skipping data file with no valid points
                                                                  ^
         x range is invalid

If I reduce the file down by hand – removing all (, ), and , to :

QuadraticBezier 106.774 78.855

the plot works (image provided if needed).

… otherwise I edit the ( ) out to avoid trouble in gnuplot. It seems the , is not the problem – and I am read help datafile section on separator, so I tried set datafile separator "()", and the using section, and while gnulplot treats the characters separating the variables quite well, the case I describe above has special characters stuck onto the variables. I could continue pursuing this but it will help to know if this will not work, etc.

gnuplot version 5.4 patchlevel 2

Ubuntu Linux 22.04.2

SO post showing a lot more about the python script output.

Answers:

If you have the following data format:

QuadraticBezier (106.774, 78.855)

and you want to extract and plot the two numbers, you need to define:

set datafile separator '(,)'

The closing parenthesis might be skipped.
If you don’t separate at the comma, the second column will be interpreted as 106.774, 78.855 which leads to a floating point number of 106.774 and the 3rd column will be empty after the closing parenthesis.

Script:

### datafile separators
reset session

$Data <<EOD
QuadraticBezier (106.774, 78.855)
QuadraticBezier (222.222, 66.666)
QuadraticBezier (333.333, 55.555)
QuadraticBezier (444.444, 44.444)
EOD

set datafile separator "(,)"

plot $Data u 3:2 w lp pt 7
### end of script

Result:

enter image description here

Answered By: theozh