脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - Python产生Gnuplot绘图数据的方法

Python产生Gnuplot绘图数据的方法

2021-04-17 00:38落叶_小唱 Python

今天小编就为大家分享一篇Python产生Gnuplot绘图数据的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

gnuplot的绘图可以直接选取文件绘图,文件格式要求如下:

x1 y1

x2 y2

......

xn yn

在python中利用文件操作的write方法可以非常方便实现,在此记录一下,这里强调s的是gnuplot的绘图,用python只是产生一下数据w而已,并不讨论python绘图和gnuplot的优劣,自己也是刚学gnuplot

python代码

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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代码

?
1
plot 'random_number.txt'

gnuplot输出结果如下:

Python产生Gnuplot绘图数据的方法

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

原文链接:https://blog.csdn.net/ouening/article/details/71915186

延伸 · 阅读

精彩推荐