From f04049f098d24eec6e8302cfe262ccee73261c43 Mon Sep 17 00:00:00 2001 From: Luke Campagnola <> Date: Mon, 22 Oct 2012 14:10:16 -0400 Subject: [PATCH] Added histogram example --- examples/__main__.py | 8 ++++++-- examples/histogram.py | 38 ++++++++++++++++++++++++++++++++++++++ graphicsWindows.py | 10 +++++----- 3 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 examples/histogram.py diff --git a/examples/__main__.py b/examples/__main__.py index bfcc6de4..a0638f5d 100644 --- a/examples/__main__.py +++ b/examples/__main__.py @@ -17,12 +17,11 @@ examples = OrderedDict([ ('ImageView', 'ImageView.py'), ('ParameterTree', 'parametertree.py'), ('Crosshair / Mouse interaction', 'crosshair.py'), - ('Video speed test', 'VideoSpeedTest.py'), - ('Plot speed test', 'PlotSpeedTest.py'), ('Data Slicing', 'DataSlicing.py'), ('Plot Customization', 'customPlot.py'), ('Dock widgets', 'dockarea.py'), ('Console', 'ConsoleWidget.py'), + ('Histograms', 'histogram.py'), ('GraphicsItems', OrderedDict([ ('Scatter Plot', 'ScatterPlot.py'), #('PlotItem', 'PlotItem.py'), @@ -37,6 +36,11 @@ examples = OrderedDict([ ('Arrow', 'Arrow.py'), ('ViewBox', 'ViewBox.py'), ])), + ('Benchmarks', OrderedDict([ + ('Video speed test', 'VideoSpeedTest.py'), + ('Line Plot update', 'PlotSpeedTest.py'), + ('Scatter Plot update', 'ScatterPlotSpeedTest.py'), + ])), ('3D Graphics', OrderedDict([ ('Volumetric', 'GLVolumeItem.py'), ('Isosurface', 'GLMeshItem.py'), diff --git a/examples/histogram.py b/examples/histogram.py new file mode 100644 index 00000000..1241f42c --- /dev/null +++ b/examples/histogram.py @@ -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_() diff --git a/graphicsWindows.py b/graphicsWindows.py index 9e5090e1..6e7d6305 100644 --- a/graphicsWindows.py +++ b/graphicsWindows.py @@ -21,13 +21,13 @@ def mkQApp(): class GraphicsWindow(GraphicsLayoutWidget): def __init__(self, title=None, size=(800,600), **kargs): mkQApp() - self.win = QtGui.QMainWindow() + #self.win = QtGui.QMainWindow() GraphicsLayoutWidget.__init__(self, **kargs) - self.win.setCentralWidget(self) - self.win.resize(*size) + #self.win.setCentralWidget(self) + self.resize(*size) if title is not None: - self.win.setWindowTitle(title) - self.win.show() + self.setWindowTitle(title) + self.show() class TabWindow(QtGui.QMainWindow):