码迷,mamicode.com
首页 > 其他好文 > 详细

matplotlib绑定到PyQt5(无菜单)

时间:2015-03-09 07:02:29      阅读:467      评论:0      收藏:0      [点我收藏+]

标签:

很简单的实现matplotlib绑定到PyQt5

 

【知识点】

1 import matplotlib
2 matplotlib.use("Qt5Agg")
3 
4 from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
5 from matplotlib.figure import Figure

 

【效果图】

技术分享

【源代码】

 1 import numpy as np
 2 import matplotlib
 3 matplotlib.use("Qt5Agg")
 4 
 5 from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
 6 from matplotlib.figure import Figure
 7 
 8 from PyQt5 import QtWidgets
 9 
10 
11 class Widget(FigureCanvas):
12     def __init__(self, parent=None, width=5, height=4, dpi=100):
13         fig = Figure(figsize=(width, height), dpi=100)
14         FigureCanvas.__init__(self, fig)
15         self.setParent(parent)
16         
17         # 散点图
18         self.axes = fig.add_subplot(211)
19         self.axes.scatter(np.random.rand(20), np.random.rand(20))
20         
21         # 折线图
22         self.axes2 = fig.add_subplot(212)
23         x = np.arange(0, 5, 0.1)
24         self.axes2.plot(x, np.sin(x), x, np.cos(x))
25 
26         self.setWindowTitle("示例:matplotlib 绑定到 PyQt5")
27 
28 if __name__ == "__main__":
29     import sys
30     app = QtWidgets.QApplication(sys.argv)
31     w = Widget()
32     w.show()
33     sys.exit(app.exec_())

 

matplotlib绑定到PyQt5(无菜单)

标签:

原文地址:http://www.cnblogs.com/hhh5460/p/4322646.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!