使用gnuplot将字符串绘制到表中 [英] Plotting strings to table with gnuplot

查看:133
本文介绍了使用gnuplot将字符串绘制到表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎在绘制表格时,一列的字符串长度显然限制为大约62个字符. 下面的代码是一个最小的示例(gnuplot 5.2.5).

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

输出:

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

推荐答案

您已发现错误,或者至少是不必要的限制. "plot with table"的每列输出长度限制为%g格式的最大宽度,但这与字符串无关.

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.

根据完整的用例,您可能可以通过基于"plot with label"的方法来解决该错误.这是一个丑陋的示例,将附加到示例代码的末尾:

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"

这篇关于使用gnuplot将字符串绘制到表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆