Added histogram example

This commit is contained in:
Luke Campagnola 2012-10-22 14:10:16 -04:00
parent 15d9c1b351
commit f04049f098
3 changed files with 49 additions and 7 deletions

View File

@ -17,12 +17,11 @@ examples = OrderedDict([
('ImageView', 'ImageView.py'), ('ImageView', 'ImageView.py'),
('ParameterTree', 'parametertree.py'), ('ParameterTree', 'parametertree.py'),
('Crosshair / Mouse interaction', 'crosshair.py'), ('Crosshair / Mouse interaction', 'crosshair.py'),
('Video speed test', 'VideoSpeedTest.py'),
('Plot speed test', 'PlotSpeedTest.py'),
('Data Slicing', 'DataSlicing.py'), ('Data Slicing', 'DataSlicing.py'),
('Plot Customization', 'customPlot.py'), ('Plot Customization', 'customPlot.py'),
('Dock widgets', 'dockarea.py'), ('Dock widgets', 'dockarea.py'),
('Console', 'ConsoleWidget.py'), ('Console', 'ConsoleWidget.py'),
('Histograms', 'histogram.py'),
('GraphicsItems', OrderedDict([ ('GraphicsItems', OrderedDict([
('Scatter Plot', 'ScatterPlot.py'), ('Scatter Plot', 'ScatterPlot.py'),
#('PlotItem', 'PlotItem.py'), #('PlotItem', 'PlotItem.py'),
@ -37,6 +36,11 @@ examples = OrderedDict([
('Arrow', 'Arrow.py'), ('Arrow', 'Arrow.py'),
('ViewBox', 'ViewBox.py'), ('ViewBox', 'ViewBox.py'),
])), ])),
('Benchmarks', OrderedDict([
('Video speed test', 'VideoSpeedTest.py'),
('Line Plot update', 'PlotSpeedTest.py'),
('Scatter Plot update', 'ScatterPlotSpeedTest.py'),
])),
('3D Graphics', OrderedDict([ ('3D Graphics', OrderedDict([
('Volumetric', 'GLVolumeItem.py'), ('Volumetric', 'GLVolumeItem.py'),
('Isosurface', 'GLMeshItem.py'), ('Isosurface', 'GLMeshItem.py'),

38
examples/histogram.py Normal file
View File

@ -0,0 +1,38 @@
# -*- 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.GraphicsWindow()
win.resize(800,350)
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)])
## draw standard histogram
y,x = np.histogram(vals, bins=np.linspace(-3, 8, 40))
## notice that len(x) == len(y)+1
## We are required to use stepMode=True so that PlotCurveItem will interpret this data correctly.
curve = pg.PlotCurveItem(x, y, stepMode=True, fillLevel=0, brush=(0, 0, 255, 80))
plt1.addItem(curve)
## Now draw all points as a nicely-spaced scatter plot
y = pg.pseudoScatter(vals, spacing=0.15)
#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))
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -21,13 +21,13 @@ def mkQApp():
class GraphicsWindow(GraphicsLayoutWidget): class GraphicsWindow(GraphicsLayoutWidget):
def __init__(self, title=None, size=(800,600), **kargs): def __init__(self, title=None, size=(800,600), **kargs):
mkQApp() mkQApp()
self.win = QtGui.QMainWindow() #self.win = QtGui.QMainWindow()
GraphicsLayoutWidget.__init__(self, **kargs) GraphicsLayoutWidget.__init__(self, **kargs)
self.win.setCentralWidget(self) #self.win.setCentralWidget(self)
self.win.resize(*size) self.resize(*size)
if title is not None: if title is not None:
self.win.setWindowTitle(title) self.setWindowTitle(title)
self.win.show() self.show()
class TabWindow(QtGui.QMainWindow): class TabWindow(QtGui.QMainWindow):