您的位置:首页 > 编程语言 > Python开发

python中PyQwt的使用 画图(一)

2013-09-24 16:57 429 查看
文章中将假设读者已经有Python的与PyQt的编码的经验,因此只会针对PyQwt的相关部分作解释。
在第一个范例中将介绍PyQwt最基本的绘制二维曲线功能,下图为程序执行后输出的图形视窗:





 

#!/usr/bin/env python

import sys

import numpy as np

from PyQt4.QtCore import *

from PyQt4.QtGui import *

from PyQt4.Qwt5 import *

class Ex01(QWidget):

def __init__(self):

QWidget.__init__(self)

fig = QwtPlot()

fig.setParent(self)

text = "f(x) = x + x<sup>2<\sup>"

fig.setTitle(text)

fig.setAxisTitle(fig.xBottom, "x")

fig.setAxisTitle(fig.yLeft, "f(x)")

x = np.arange(0, 10, 0.1)

y = x +x**2

curve = QwtPlotCurve()

curve.setData(x, y)

curve.attach(fig)

fig.replot()

fig.resize(400, 300)

def main():

app = QApplication(sys.argv)

frame = Ex01()

frame.show()

app.exec_()

if __name__ == "__main__":

main()


 

 

一开始我们导入必要的库,其中PyQt4.Qwt5即为PyQwt库。

在类Ex01中分别创建 QwtPlot对象,通过调用QwtPlot对象的方法setTitle(String)来设定图的标题文字。而setAxisTitle(AxisId,String)用来设定座标轴的标题。fig.xBottm 和 fig.yLeft 为
QwtPlot对象的属性,分別代表 fig 的下方 x 轴和左边的y轴。
转自:http://blog.chinaunix.net/uid-25979788-id-2943083.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: