在 Gnuplot 中包装标题

Exp*_*oob 2 gnuplot

这一切都在主题中。我使用数据文件中的(长)行作为标题,而 Gnuplot 不包装它。

我事先不知道该行的内容,所以我不知道如何插入\n. 如何让 Gnuplot 包装标题?

Vic*_*ten 5

您应该编辑文件中的数据并\n在解析标题的字段中插入 a 。

Gnuplot 将识别\n并在该点断线。否则,您需要手动输入标题并\n在您想要的位置添加。

重要的是要注意,\n如果你有"string"而不是'string'.

如果您无法编辑文件中的数据,则可以使用 gnuplot 中的字符串函数。有了strlen("string")你可以找到你的字符串的长度,然后用substr("string",begin,end)你可以分割你的字符串。

这是 gnuplot 函数的完整列表:http :
//gnuplot.sourceforge.net/docs_4.2/node53.html

总之,你会有类似的东西

foo = "my data"
length = strlen(foo)                   #get string length
length2 = sprintf("%1.d", length / 2)  #round halved down string length to find center char
foo1 = substr(foo, 0, length2)         #get first half of string
foo2 = substr(foo, length2, length)    #get second half of string
titlestring = foo1.\n.foo2             #make new title string with newline character 
Run Code Online (Sandbox Code Playgroud)

更多细节参考gnuplot的字符串变量演示脚本:http :
//gnuplot.sourceforge.net/demo/stringvar.html

给出了这样的例子:

#
# Miscellaneous neat things you can do using the string variables code
#
set print "stringvar.tmp"
print ""
print "Exercise substring handling"
print ""
beg = 2
end = 4
print "beg = ",beg," end = ",end
foo = "ABCDEF"
print "foo           = ",foo
print "foo[3:5]      = ",foo[3:5]
print "foo[1:1]      = ",foo[1:1]
print "foo[5:3]      = ",foo[5:3]
print "foo[beg:end]  = ",foo[beg:end]
print "foo[end:beg]  = ",foo[end:beg]
print "foo[5:]       = ",foo[5:]
print "foo[5:*]      = ",foo[5:*]
print "foo[:]        = ",foo[:]
print "foo[*:*]      = ",foo[*:*]
print "foo.foo[2:2]  = ",foo.foo[2:2]
print "(foo.foo)[2:2]= ",(foo.foo)[2:2]
print ""
print "foo[1:1] eq 'A' && foo[2:2] ne 'X' = ", \
      (foo[1:1] eq 'A' && foo[2:2] ne 'X') ? "true" : "false"

unset print

set label 1 system("cat stringvar.tmp") at graph 0.1, graph 0.9
unset xtics
unset ytics
set yrange [0:1]
plot 0
Run Code Online (Sandbox Code Playgroud)

连同该函数,strlen您应该能够构建您的解决方案以自动处理 gnuplot 中的数据并将换行符放置在您想要的位置(例如每 20 个字符之后)。

如果你想打破的话,你会使用:

wordnumber = word(foo)                           #get number of words
wordernumber2 = sprintf("%1.d", wordnumber / 2)  #round down half of #words
do for [i=0:wordnumber2] {                       #add half of words to string
    string = string.word(foo,i)
}
string = string.\n                               #add newline to string
do for [i=wordnumber2:wordnumber] {              #add 2nd half of words
    string = string.word(foo,i)
}
Run Code Online (Sandbox Code Playgroud)

这需要 gnuplot 4.4+