我不想在這裏做任何事。我試圖在下面的腳本中自動繪製一些實驗數據: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/ –