Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1503338
  • 博文数量: 164
  • 博客积分: 2993
  • 博客等级: 少校
  • 技术积分: 1718
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-24 11:42
文章分类

全部博文(164)

文章存档

2014年(1)

2013年(36)

2012年(90)

2011年(37)

分类: Python/Ruby

2011-10-08 16:50:45

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

下面是程序编码:

  1. #!/usr/bin/env python
  2. import sys
  3. import numpy as np
  4. from PyQt4.QtCore import *
  5. from PyQt4.QtGui import *
  6. from PyQt4.Qwt5 import *
  7. class Ex01(QWidget):
  8.     def __init__(self):
  9.         QWidget.__init__(self)
  10.         fig = QwtPlot()
  11.         fig.setParent(self)
  12.         text = "f(x) = x + x2<\sup>"
  13.         fig.setTitle(text)
  14.         fig.setAxisTitle(fig.xBottom, "x")
  15.         fig.setAxisTitle(fig.yLeft, "f(x)")
  16.         x = np.arange(0, 10, 0.1)
  17.         y = x +x**2
  18.         curve = QwtPlotCurve()
  19.         curve.setData(x, y)
  20.         curve.attach(fig)
  21.         fig.replot()
  22.         fig.resize(400, 300)
  23. def main():
  24.     app = QApplication(sys.argv)
  25.     frame = Ex01()
  26.     frame.show()
  27.     app.exec_()
  28. if __name__ == "__main__":
  29.     main()

一开始我们导入必要的库其中PyQt4.Qwt5即为PyQwt库
在类Ex01中分别创建 QwtPlot对象,通过调用
QwtPlot对象的方法setTitle(String)来设定标题文字setAxisTitleAxisId,String)用来设定座标标题。fig.xBottm 和 fig.yLeft 为 QwtPlot对象的属性,分別代表 fig 的下方 x 轴和左边的y轴。

 

阅读(7451) | 评论(0) | 转发(0) |
0

上一篇:python安装scrapy库

下一篇:python使用sqlite3

给主人留下些什么吧!~~