当前位置: 移动技术网 > IT编程>脚本编程>Python > Python产生Gnuplot绘图数据的方法

Python产生Gnuplot绘图数据的方法

2019年06月14日  | 移动技术网IT编程  | 我要评论

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路径下生成的文件,内容如下:

python产生gnuplot绘图数据

注意gnuplot的工作路径也要选择到d:\files\gnuplot ,然后执行下列代码

gnuplot代码

plot 'random_number.txt'

gnuplot输出结果如下:

python产生gnuplot绘图数据

以上这篇python产生gnuplot绘图数据的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网