Gnuplot设置编码为utf8无效。

4

我在Windows 8系统上安装了gnuplot (版本4.6 patchlevel 5)。我想设置UTF8编码方式。我的源文件已经保存为UTF-8编码。我的源文件名为test.txt:

set terminal pdf enhanced size 16cm,8cm font ", 10"
set output "Slozitost/Slozitost.pdf"
set encoding utf8
set grid
set datafile separator ","
set title "Složitost" font ",10"
set key left top title "Legenda" box
set xdata time 
set timefmt "%d/%m/%Y"
set xrange ["03/01/2009":"20/04/2014"]
set format y "%10.0f"
#set yrange [-50:14000000]
set format x "%m/%y"
set xtics 6*30*24*60*60
#set ytics 100
set lmargin  13
set rmargin  2
set style fill transparent solid 0.5 noborder
plot 'Slozitost.csv' using 1:2 title "Slozitost" with lines linecolor rgb "blue" lw 3

我尝试通过gnuplot终端编译源代码。Gnuplot终端向我报告了以下错误:

gnuplot> load "test.txt"
          ^
         "test.txt", line 1: invalid character »

有什么问题吗?


这个错误似乎发生在你代码的第一行,在你实际设置编码之前。老实说,我没有关于 gnuplot 编码的经验,但看起来 gnuplot 不喜欢你脚本中的某些字符。只是一个想法:你尝试过在 load "test.txt" 之前先用 set encoding utf8 吗? - Miguel
是的,它做了同样的事情,但我不明白为什么终端无法识别test.txt(test.txt采用utf8编码)。 - user3473712
1个回答

5

如果你的文件开头有BOM标记,这种情况可能会发生。Gnuplot无法处理这种情况。要删除它,请参阅编辑器的文档。

如果这是错误的源,那么如果将代码复制并粘贴到交互式终端中,则代码应该可以正常运行。

顺便说一下:没有必要发布我们无法运行的如此庞大的脚本(我们没有数据文件)。一个可以显示问题的最小脚本可能是这样的:

set encoding utf8
plot x title "Složitost"

这也将缩小您问题的来源范围 :)

1
当我在gnuplot终端(在Windows上)中写下这些字母“řřšřšřý”时,终端无法识别它们。这也很奇怪... - user3473712
这显然不是解决您问题的方法,但也许您可以看一下其中一个LaTeX终端,并通过LaTeX语法输入您的特殊文本。 - Miguel
提供的最小脚本是否有效:1.当您将其复制并粘贴到gnuplot终端时?2.当您将其写入文件并使用load 'myfile.txt'加载时? - Christoph

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接