theozh
theozh

Reputation: 25714

Plotting strings to table with gnuplot

It seems like when plotting to a table the string length of a column is apparently limited to about 62 characters. The code below is a minimal example (gnuplot 5.2.5).

Why is the string length limited to such a "small" value? Is there a way around to be able to use longer strings?

### plot dataset to table including strings
reset session

$DataInput <<EOD
# tab separated data
1   0.123   This is some text, actually a lot of text, which apparently is too much for gnuplot.    84
2   0.456   This is some text, actually a lot of text, which apparently is too much.    72
3   0.789   This is some text, actually a lot of text.  42
EOD

set datafile commentschar ""
set datafile separator "\n"
set table $DataOutput
    plot $DataInput u (stringcolumn(1)) with table
unset table
set datafile separator "\t"
set datafile commentschar "#"

print "DataInput:"
print $DataInput

print "DataOutput:"
print $DataOutput

### end of code

Output:

DataInput:
# tab separated data
1   0.123   This is some text, actually a lot of text, which apparently is too much for gnuplot.    84
2   0.456   This is some text, actually a lot of text, which apparently is too much.    72
3   0.789   This is some text, actually a lot of text.  42

DataOutput:
 # tab separated data   
 1  0.123   This is some text, actually a lot of text, which appar
 2  0.456   This is some text, actually a lot of text, which appar
 3  0.789   This is some text, actually a lot of text.  42

Upvotes: 1

Views: 1468

Answers (1)

Ethan
Ethan

Reputation: 15093

You have found a bug, or at least an unnecessary limitation. The per-column output length from "plot with table" is limited to the maximum width of the %g format, but that is irrelevant for strings.

Depending on the full use case you might be able to work around the bug by something based on "plot with label". Here is an ugly example to be appended to the end of your sample code:

print "\ndirect output to table with labels"
set table $LabelOutput
    plot $DataInput using (0):(0):(stringcolumn(1)) with labels
unset table
print $LabelOutput

print "\n Edited version"
do for [i=1:|$LabelOutput|] {
    print $LabelOutput[i][1:1], $LabelOutput[i][7:*]
}

Output (yeah, the comments are mangled and I didn't remove the quotes):

direct output to table with labels

# Curve 0 of 1, 4 points
# Curve title: "$DataInput using (0):(0):(stringcolumn(1))"
# x y label type
 0  0 "# tab separated data"
 0  0 "1   0.123   This is some text, actually a lot of text, which apparently is too much for gnuplot.    84"
 0  0 "2   0.456   This is some text, actually a lot of text, which apparently is too much.    72"
 0  0 "3   0.789   This is some text, actually a lot of text.  42"



 Edited version

#e 0 of 1, 4 points
#e title: "$DataInput using (0):(0):(stringcolumn(1))"
#label type
 "# tab separated data"
 "1   0.123   This is some text, actually a lot of text, which apparently is too much for gnuplot.    84"
 "2   0.456   This is some text, actually a lot of text, which apparently is too much.    72"
 "3   0.789   This is some text, actually a lot of text.  42"

Upvotes: 2

Related Questions