pyqtgraph/examples/histogram.py

37 lines
1.3 KiB
Python
Raw Normal View History

2012-10-22 18:10:16 +00:00
# -*- coding: utf-8 -*-
"""
In this example we draw two different kinds of histogram.
"""
import initExample ## Add path to library (just for examples; you do not need this)
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
win = pg.GraphicsLayoutWidget(show=True)
2012-10-22 18:10:16 +00:00
win.resize(800,350)
2013-02-25 04:09:03 +00:00
win.setWindowTitle('pyqtgraph example: Histogram')
2012-10-22 18:10:16 +00:00
plt1 = win.addPlot()
plt2 = win.addPlot()
## make interesting distribution of values
vals = np.hstack([np.random.normal(size=500), np.random.normal(size=260, loc=4)])
2013-02-25 04:09:03 +00:00
## compute standard histogram
2012-10-22 18:10:16 +00:00
y,x = np.histogram(vals, bins=np.linspace(-3, 8, 40))
2014-04-12 22:01:50 +00:00
## Using stepMode=True causes the plot to draw two lines for each sample.
2012-10-22 18:10:16 +00:00
## notice that len(x) == len(y)+1
plt1.plot(x, y, stepMode=True, fillLevel=0, fillOutline=True, brush=(0,0,255,150))
2012-10-22 18:10:16 +00:00
## Now draw all points as a nicely-spaced scatter plot
y = pg.pseudoScatter(vals, spacing=0.15)
2014-04-12 22:01:50 +00:00
#plt2.plot(vals, y, pen=None, symbol='o', symbolSize=5)
plt2.plot(vals, y, pen=None, symbol='o', symbolSize=5, symbolPen=(255,255,255,200), symbolBrush=(0,0,255,150))
2012-10-22 18:10:16 +00:00
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()