从python调用gnuplot [英] Calling gnuplot from python

查看:114
本文介绍了从python调用gnuplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个python脚本,经过一番计算后,它将生成两个格式为gnuplot输入的数据文件.

I've a python script that after some computing will generate two data files formatted as gnuplot input.

如何从python中调用" gnuplot?

How do I 'call' gnuplot from python ?

我想将以下python字符串作为输入发送到gnuplot:

I want to send the following python string as input to gnuplot:

"plot '%s' with lines, '%s' with points;" % (eout,nout)

其中' eout '和' nout '是两个文件名.

where 'eout' and 'nout' are the two filenames.

PS: 我更喜欢,不要使用其他python模块(例如gnuplot-py),而只能使用标准API.

PS: I prefer not to use additional python modules (eg. gnuplot-py), only the standard API.

谢谢

推荐答案

一种简单的方法可能是只编写包含gnuplot命令的第三个文件,然后告诉Python用该文件执行gnuplot.假设您写

A simple approach might be to just write a third file containing your gnuplot commands and then tell Python to execute gnuplot with that file. Say you write

"plot '%s' with lines, '%s' with points;" % (eout,nout)

到名为tmp.gp的文件.然后您可以使用

to a file called tmp.gp. Then you can use

from os import system, remove
system('gnuplot tmp.gp')
remove('tmp.gp')

这篇关于从python调用gnuplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆