gnuplot的繪圖可以直接選取文件繪圖,文件格式要求如下:
x1 y1
x2 y2
......
xn yn
在python中利用文件操作的write方法可以非常方便實現,在此記錄一下,這里強調s的是gnuplot的繪圖,用python只是產生一下數據w而已,并不討論python繪圖和gnuplot的優劣,自己也是剛學gnuplot
Python代碼
import osimport randomimport mathos.chdir(u"d://Files//gnuplot")file = open("random_number.txt",'w+')for i in range(200): file.write(str(i+random.random())) file.write(' ') file.write(str(math.log10(i+random.randint(-3,7)))) file.write('/n')file.close()
打開d://Files//gnuplot路徑下生成的文件,內容如下:
注意gnuplot的工作路徑也要選擇到d:/Files/gnuplot ,然后執行下列代碼
gnuplot代碼
plot 'random_number.txt'
gnuplot輸出結果如下:
以上這篇Python產生Gnuplot繪圖數據的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。
新聞熱點
疑難解答