Skip to content

Instantly share code, notes, and snippets.

@Overdrivr
Created February 4, 2016 13:38
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Overdrivr/ed140520493e5d0f248d to your computer and use it in GitHub Desktop.
Save Overdrivr/ed140520493e5d0f248d to your computer and use it in GitHub Desktop.
PyQtGraph animated sine and cosine functions - real smooth
# -*- 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()
@nithinivi
Copy link

Following error is returned on setting up the antialias options. Using pyqtgraph (0.10.0)

 p.setConfigOptions(antialias=True)
  raise NameError(attr)
NameError: setConfigOptions

Thanks in advance for your time

@RishikMani
Copy link

RishikMani commented Jan 22, 2018

Thank you very much, somehow your code helped me in resolving an issue with my PyQtGraph.

@rudrathegreat
Copy link

I am getting the error that python has stopped working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment