Created
February 4, 2016 13:38
-
-
Save Overdrivr/ed140520493e5d0f248d to your computer and use it in GitHub Desktop.
PyQtGraph animated sine and cosine functions - real smooth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from pyqtgraph.Qt import QtGui, QtCore | |
import numpy as np | |
from numpy import arange, sin, cos, pi | |
import pyqtgraph as pg | |
import sys | |
class Plot2D(): | |
def __init__(self): | |
self.traces = dict() | |
#QtGui.QApplication.setGraphicsSystem('raster') | |
self.app = QtGui.QApplication([]) | |
#mw = QtGui.QMainWindow() | |
#mw.resize(800,800) | |
self.win = pg.GraphicsWindow(title="Basic plotting examples") | |
self.win.resize(1000,600) | |
self.win.setWindowTitle('pyqtgraph example: Plotting') | |
# Enable antialiasing for prettier plots | |
pg.setConfigOptions(antialias=True) | |
self.canvas = self.win.addPlot(title="Pytelemetry") | |
def start(self): | |
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): | |
QtGui.QApplication.instance().exec_() | |
def trace(self,name,dataset_x,dataset_y): | |
if name in self.traces: | |
self.traces[name].setData(dataset_x,dataset_y) | |
else: | |
self.traces[name] = self.canvas.plot(pen='y') | |
## Start Qt event loop unless running in interactive mode or using pyside. | |
if __name__ == '__main__': | |
p = Plot2D() | |
i = 0 | |
def update(): | |
global p, i | |
t = np.arange(0,3.0,0.01) | |
s = sin(2 * pi * t + i) | |
c = cos(2 * pi * t + i) | |
p.trace("sin",t,s) | |
p.trace("cos",t,c) | |
i += 0.1 | |
timer = QtCore.QTimer() | |
timer.timeout.connect(update) | |
timer.start(50) | |
p.start() |
Thank you very much, somehow your code helped me in resolving an issue with my PyQtGraph.
I am getting the error that python has stopped working
This wasn't working for me, I updated the following lines to fix:
self.app = QtGui.QApplication([]) #old
self.app = pg.mkQApp() #new
self.win = pg.GraphicsWindow(title="Basic plotting examples") #old
self.win = pg.GraphicsLayoutWidget(show=True, title="Basic plotting examples") #new
QtGui.QApplication.instance().exec_() #old
pg.exec() #new
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Following error is returned on setting up the antialias options. Using pyqtgraph (0.10.0)
Thanks in advance for your time