我不想在这里做任何事。我试图在下面的脚本中自动绘制一些实验数据:Python子流程:如何管道到gnuplot命令来绘制一个变量?
print "processing: ", filename
gnuplot = Popen(gnuplot_bin,stdin = PIPE).stdin
if state_plot:
gnuplot.write("set term x11\n".encode())
gnuplot.write("set term png size 1920,1010 \n".encode())
gnuplot.write("set output \"acceleration.png\" \n".encode())
gnuplot.write("set xlabel \"timesteps\" \n".encode())
gnuplot.write("set ylabel \"acceleration\" \n".encode())
gnuplot.write("plot " %filename " using 1 with lines lt -1 lw 0.5 title 'X axis' \n " .encode())
gnuplot.write(" " %filename " using 2 with lines lt 1 lw 0.5 title 'Y axis' \n " .encode())
gnuplot.write(" " %filename " using 3 with lines lt 2 lw 0.5 title 'Z axis' \n " .encode())
但是,文件名是从字面上理解的。我从gnuplot的出现以下错误:
线0:警告:跳过不可读文件“”%文件名“” 线0:剧情
我已经从SYS解析的文件名没有任何数据。 argv并确保它是正确和安全的,现在我需要告诉gnuplot来绘制文件名被设置为的任何名称。 我试过使用转义字符,删除ambersand,但我显然使用了错误的语法。
有人可以帮忙吗?
编辑:
感谢对AGF我已经解决了蟒蛇格式化问题:
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的一个问题。通常情况下,直接使用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似乎会导致错误:
gnuplot> plot "state_log_6548032.data" using 1 with lines lt -1 lw 0.5 title 'X axis' ,\
^
line 0: invalid character \
gnuplot> "state_log_6548032.data" using 2 with lines lt 1 lw 0.5 title 'Y axis' ,\
^
line 0: invalid character \
gnuplot> "state_log_6548032.data" using 3 with lines lt 2 lw 0.5 title 'Z axis'
^
line 0: invalid command
我打赌它与做的,\和换行符?
这不是仍然编程和维持,但要尽量看看这里:http://gnuplot-py.sourceforge.net/ –