Python产生Gnuplot绘图数据的方法
时间:2021-02-11 11:18:28|栏目:Python代码|点击: 次
gnuplot的绘图可以直接选取文件绘图,文件格式要求如下:
x1 y1
x2 y2
......
xn yn
在python中利用文件操作的write方法可以非常方便实现,在此记录一下,这里强调s的是gnuplot的绘图,用python只是产生一下数据w而已,并不讨论python绘图和gnuplot的优劣,自己也是刚学gnuplot
Python代码
import os
import random
import math
os.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输出结果如下:







