2012-03-02 02:55:32 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-02-25 04:09:03 +00:00
|
|
|
"""
|
|
|
|
This example demonstrates many of the 2D plotting capabilities
|
|
|
|
in pyqtgraph. All of the plots may be panned/scaled by dragging with
|
|
|
|
the left/right mouse buttons. Right click on any plot to show a context menu.
|
|
|
|
"""
|
2012-03-17 15:47:20 +00:00
|
|
|
|
|
|
|
import initExample ## Add path to library (just for examples; you do not need this)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
|
2012-03-02 03:53:52 +00:00
|
|
|
from pyqtgraph.Qt import QtGui, QtCore
|
2012-03-02 02:55:32 +00:00
|
|
|
import numpy as np
|
|
|
|
import pyqtgraph as pg
|
|
|
|
|
|
|
|
#QtGui.QApplication.setGraphicsSystem('raster')
|
|
|
|
app = QtGui.QApplication([])
|
|
|
|
#mw = QtGui.QMainWindow()
|
|
|
|
#mw.resize(800,800)
|
|
|
|
|
2018-02-16 04:15:32 +00:00
|
|
|
win = pg.GraphicsLayoutWidget(show=True, title="Basic plotting examples")
|
2012-12-23 05:51:28 +00:00
|
|
|
win.resize(1000,600)
|
2013-02-25 04:09:03 +00:00
|
|
|
win.setWindowTitle('pyqtgraph example: Plotting')
|
2012-03-02 02:55:32 +00:00
|
|
|
|
2013-03-26 17:46:26 +00:00
|
|
|
# Enable antialiasing for prettier plots
|
|
|
|
pg.setConfigOptions(antialias=True)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
p1 = win.addPlot(title="Basic array plotting", y=np.random.normal(size=100))
|
|
|
|
|
|
|
|
p2 = win.addPlot(title="Multiple curves")
|
2013-12-19 17:30:00 +00:00
|
|
|
p2.plot(np.random.normal(size=100), pen=(255,0,0), name="Red curve")
|
2016-03-27 15:09:06 +00:00
|
|
|
p2.plot(np.random.normal(size=110)+5, pen=(0,255,0), name="Green curve")
|
|
|
|
p2.plot(np.random.normal(size=120)+10, pen=(0,0,255), name="Blue curve")
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
p3 = win.addPlot(title="Drawing with points")
|
|
|
|
p3.plot(np.random.normal(size=100), pen=(200,200,200), symbolBrush=(255,0,0), symbolPen='w')
|
|
|
|
|
|
|
|
|
|
|
|
win.nextRow()
|
|
|
|
|
2012-04-21 19:57:47 +00:00
|
|
|
p4 = win.addPlot(title="Parametric, grid enabled")
|
2012-03-02 02:55:32 +00:00
|
|
|
x = np.cos(np.linspace(0, 2*np.pi, 1000))
|
|
|
|
y = np.sin(np.linspace(0, 4*np.pi, 1000))
|
|
|
|
p4.plot(x, y)
|
2012-04-21 19:57:47 +00:00
|
|
|
p4.showGrid(x=True, y=True)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
2012-04-21 19:57:47 +00:00
|
|
|
p5 = win.addPlot(title="Scatter plot, axis labels, log scale")
|
2012-03-02 02:55:32 +00:00
|
|
|
x = np.random.normal(size=1000) * 1e-5
|
|
|
|
y = x*1000 + 0.005 * np.random.normal(size=1000)
|
2012-04-21 19:57:47 +00:00
|
|
|
y -= y.min()-1.0
|
2013-01-12 01:21:11 +00:00
|
|
|
mask = x > 1e-15
|
|
|
|
x = x[mask]
|
|
|
|
y = y[mask]
|
2012-03-02 02:55:32 +00:00
|
|
|
p5.plot(x, y, pen=None, symbol='t', symbolPen=None, symbolSize=10, symbolBrush=(100, 100, 255, 50))
|
|
|
|
p5.setLabel('left', "Y Axis", units='A')
|
|
|
|
p5.setLabel('bottom', "Y Axis", units='s')
|
2012-04-21 19:57:47 +00:00
|
|
|
p5.setLogMode(x=True, y=False)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
p6 = win.addPlot(title="Updating plot")
|
|
|
|
curve = p6.plot(pen='y')
|
|
|
|
data = np.random.normal(size=(10,1000))
|
|
|
|
ptr = 0
|
|
|
|
def update():
|
|
|
|
global curve, data, ptr, p6
|
|
|
|
curve.setData(data[ptr%10])
|
|
|
|
if ptr == 0:
|
2012-03-18 18:57:36 +00:00
|
|
|
p6.enableAutoRange('xy', False) ## stop auto-scaling after the first data set is plotted
|
2012-03-02 02:55:32 +00:00
|
|
|
ptr += 1
|
|
|
|
timer = QtCore.QTimer()
|
|
|
|
timer.timeout.connect(update)
|
|
|
|
timer.start(50)
|
|
|
|
|
|
|
|
|
|
|
|
win.nextRow()
|
|
|
|
|
2012-04-21 19:57:47 +00:00
|
|
|
p7 = win.addPlot(title="Filled plot, axis disabled")
|
2012-03-02 02:55:32 +00:00
|
|
|
y = np.sin(np.linspace(0, 10, 1000)) + np.random.normal(size=1000, scale=0.1)
|
|
|
|
p7.plot(y, fillLevel=-0.3, brush=(50,50,200,100))
|
2012-04-21 19:57:47 +00:00
|
|
|
p7.showAxis('bottom', False)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
|
2012-03-09 17:38:15 +00:00
|
|
|
x2 = np.linspace(-100, 100, 1000)
|
|
|
|
data2 = np.sin(x2) / x2
|
|
|
|
p8 = win.addPlot(title="Region Selection")
|
|
|
|
p8.plot(data2, pen=(255,255,255,200))
|
|
|
|
lr = pg.LinearRegionItem([400,700])
|
|
|
|
lr.setZValue(-10)
|
|
|
|
p8.addItem(lr)
|
|
|
|
|
|
|
|
p9 = win.addPlot(title="Zoom on selected region")
|
|
|
|
p9.plot(data2)
|
2012-04-22 17:22:43 +00:00
|
|
|
def updatePlot():
|
|
|
|
p9.setXRange(*lr.getRegion(), padding=0)
|
|
|
|
def updateRegion():
|
|
|
|
lr.setRegion(p9.getViewBox().viewRange()[0])
|
|
|
|
lr.sigRegionChanged.connect(updatePlot)
|
|
|
|
p9.sigXRangeChanged.connect(updateRegion)
|
|
|
|
updatePlot()
|
2012-03-09 17:38:15 +00:00
|
|
|
|
2012-03-17 15:47:20 +00:00
|
|
|
## Start Qt event loop unless running in interactive mode or using pyside.
|
2012-12-05 05:25:45 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
|
|
|
|
QtGui.QApplication.instance().exec_()
|