通常使用交互式GNUPLOT我在做的事:gnuplot的蟒蛇发送换行和“ ”
gnuplot> plot "state_log_6548032.data" using 4 with lines lt -1 lw 0.5 title "X axis" ,\
>"state_log_6548032.data" using 5 with lines lt 1 lw 0.5 title "Y axis" ,\
>"state_log_6548032.data" using 6 with lines lt 2 lw 0.5 title "Z axis"
然而,当我尝试使用子从蟒蛇做同样的:
gnuplot.write("plot \"%s\" using 1 with lines lt -1 lw 0.5 title 'X axis' ,\ \n" %filename)
gnuplot.write("plot \"%s\" using 2 with lines lt 1 lw 0.5 title 'Y axis' ,\ \n" %filename)
gnuplot.write("plot \"%s\" using 3 with lines lt 2 lw 0.5 title 'Z axis' \n" %filename)
我得到以下错误:
gnuplot> plot "state_log_6548032.data" using 1 with lines lt -1 lw 0.5 title 'X axis' ,\
^
line 0: invalid character \
gnuplot> plot "state_log_6548032.data" using 2 with lines lt 1 lw 0.5 title 'Y axis' ,\
^
line 0: invalid character \
我花了很多时间试图找出pytho是否有问题n,但我发现这是gnuplot的一个问题,从控制台调用时出于某种原因使用转义字符,但在我的情况下不需要。但是我的问题依然存在我怎样才能通过管道指令来从python子进程绘制连续行中的^^以上的数据,或者通过从python创建一个gnu文件并调用gnuplot子进程来使用该文件?
编辑:
为了任何人谁可能永远陷在这个简单的小东西:由民间好看谁保持这个社会活着解释如下,巨蟒当您使用“\”转义“\”。 因此,解决办法很干脆:
gnuplot.write("plot \"%s\" using 1 with lines lt -1 lw 0.5 title 'X axis' ,\\\n" %filename)
gnuplot.write("\"%s\" using 2 with lines lt 1 lw 0.5 title 'Y axis' ,\\\n" %filename)
gnuplot.write("\"%s\" using 3 with lines lt 2 lw 0.5 title 'Z axis' \n" %filename)
你有没有试过[gnuplot模块](http://gnuplot-py.sourceforge.net/)?另外,如果我可以推荐使用[matplotlib](http://matplotlib.sourceforge.net/)来进行绘图。 – Keith
@Keith我有debian的python-gnuplot-1.8,但我找不到任何有关如何使用它的文档。它似乎没有维护。我不知道matplotlib,非常感谢你的链接,这看起来更像我之后的第一个地方! –