通常使用交互式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,非常感謝你的鏈接,這看起來更像我之後的第一個地方! –