# -*- coding: utf-8 -*-

 import sys
from PyQt5 import QtWidgets import numpy as np
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.animation import FuncAnimation class MyMplCanvas(FigureCanvas):
"""Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.)."""
def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
# We want the axes cleared every time plot() is called
self.axes.hold(False) self.compute_initial_figure() #
FigureCanvas.__init__(self, fig)
self.setParent(parent) def compute_initial_figure(self):
pass class AnimationWidget(QtWidgets.QWidget):
def __init__(self):
QtWidgets.QWidget.__init__(self) vbox = QtWidgets.QVBoxLayout()
self.canvas = MyMplCanvas(self, width=5, height=4, dpi=100)
vbox.addWidget(self.canvas) hbox = QtWidgets.QHBoxLayout()
self.start_button = QtWidgets.QPushButton("start", self)
self.stop_button = QtWidgets.QPushButton("stop", self)
self.start_button.clicked.connect(self.on_start)
self.stop_button.clicked.connect(self.on_stop)
hbox.addWidget(self.start_button)
hbox.addWidget(self.stop_button)
vbox.addLayout(hbox)
self.setLayout(vbox) self.x = np.linspace(0, 5*np.pi, 400)
self.p = 0.0
self.y = np.sin(self.x + self.p)
self.line, = self.canvas.axes.plot(self.x, self.y, animated=True, lw=2) def update_line(self, i):
self.p += 0.1
y = np.sin(self.x + self.p)
self.line.set_ydata(y)
return [self.line] def on_start(self):
self.ani = FuncAnimation(self.canvas.figure, self.update_line,
blit=True, interval=25) def on_stop(self):
self.ani._stop() if __name__ == "__main__":
qApp = QtWidgets.QApplication(sys.argv)
aw = AnimationWidget()
aw.show()
sys.exit(qApp.exec_())

PyQt5嵌入matplotlib动画的更多相关文章

  1. PyQt5 结合 matplotlib 时,如何显示其 NavigationToolbar

    本文目的:展示 PyQt5 结合 matplotlib 时,如何显示其 NavigationToolbar. 本人搜遍所有网络无果,没办法,查看PyQt5源代码,最终才搞明白...特此留记. 〇.Py ...

  2. pyqt5 QGraphicsView颜色动画问题(不兼容,运行不了动画)

    初学动画.无敌踩坑,资料真的是太少了.....本坑是一个大坑,只有解决方法,但实质原因仍不清楚 在一篇资料中了解到我们可以通过QGraphicsView来实现动画QPropertyAnimation ...

  3. matplotlib动画

    注意:要有动画效果,必须独立窗口:独立窗口的设置方法:https://www.cnblogs.com/liming19680104/p/10614070.html import matplotlib. ...

  4. [PyQt5]动态显示matplotlib作图(一)

    完整实例 import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QMenu, QVBoxLayout, QSizePoli ...

  5. matplotlib绑定到PyQt5(有菜单)

    稍微复杂地实现matplotlib绑定到PyQt5(有菜单) [知识点] import matplotlib matplotlib.use("Qt5Agg") [效果图] [源代码 ...

  6. python 下 tinker、matplotlib 混合编程示例一个

    该例是实现了 Tinker 嵌入 matplotlib 所绘制的蜡烛图(k 线),数据是从 csv 读入的.花一下午做的,还很粗糙,仅供参考.python 代码如下: import matplotli ...

  7. pyqt中使用matplotlib绘制动态曲线

    一.项目背景: 看了matplotlib for python developers这本书,基本掌握了在pyqt中显示曲线的做法,于是自己写一个. 二.需求描述: 1)X轴显示时间点,显示长度为1分钟 ...

  8. pyqt中使用matplotlib绘制动态曲线 – pythonic

    一.项目背景: 看了matplotlib for python developers这本书,基本掌握了在pyqt中显示曲线的做法,于是自己写一个. 二.需求描述: 1)X轴显示时间点,显示长度为1分钟 ...

  9. matplotlib之pyplot 学习示例

    现在通过numpy和matplotlib.pyplot 在Python上实现科学计算和绘图,而且和matlab极为相像(效率差点,关键是方便简单) 这里有大量plots代码例子.  1. 简单的绘图( ...

随机推荐

  1. 自动生成MyEclipse 安装破解码

    新建一个class 文件,Debug 模式运行一个,输入任意值 ,回车得到破解安装码 代码文件如下: import java.io.*; public class MyEclipseGen { pri ...

  2. Pod install 之后 no such module

    官方文档在pod install之后的操作是: open App.xcworkspace 使用pod以后,项目的旧打开方式就不行了,必须到项目目录里面,打开“项目名.xcworkspace”这种方式来 ...

  3. QQ connect client request's parameters are invalid, invalid openid 问题的解决

    很多人的这个问题是POST的时候发生,我的也恰好在POST的时候发生.后来我发现可能是因为QQ的这个后端是采用类PHP的语言开发,在动态语言的获取参数时POST参数和GET参数是可以分开读取的,也就是 ...

  4. I want to try to improve myself from today

    I involved in the Internet of Things project team in my university in 2015 and now I have completed ...

  5. Linux——浅析信号处理

    信号及其处理 信号处理是Unix和LInux系统为了响应某些状况而产生的事件,通常内核产生信号,进程收到信号后采取相应的动作. 例如当我们想强制结束一个程序的时候,我们通常会给它发送一个信号,然后该进 ...

  6. 使图片自适应div大小

    <img src=“” onload="javascript:if(this.height>MaxHeight)this.height=MaxHeight;if(this.wid ...

  7. Python_排版函数

    import textwrap doc='''Beautiful is better than ugly. Explicit is better than implicit. Simple is be ...

  8. Unite Beijing 2018 参会简要分享

    一. Training Day 主讲人:鲍建运 操作:马瑞 课程包括较为完整的功能,如灯光设置,角色动画控制,Cinemachine,Timeline,AI寻路,以及最新的Post Processin ...

  9. Maven学习(三)-- 使用Maven构建项目

    摘自:http://www.cnblogs.com/xdp-gacl/p/4240930.html maven作为一个高度自动化构建工具,本身提供了构建项目的功能,下面就来体验一下使用maven构建项 ...

  10. float的范围和有效位

    首先说一下: 范围是3.4E-38 ——3.4E+38,可提供7位有效数字. 上述这两个量都是近似值,各个编译器不太一样的. 下面我就将标准值是怎么定义的,和你说一下: 这个比较复杂,建议你找一下IE ...