python3 fixes

cleaned up examples
This commit is contained in:
Luke Campagnola 2013-02-24 23:09:03 -05:00
parent 1d2d7be733
commit 491aee0fe2
60 changed files with 302 additions and 93 deletions

View File

@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-
"""
Display an animated arrowhead following a curve.
This example uses the CurveArrow class, which is a combination
of ArrowItem and CurvePoint.
## Display an animated arrowhead following a curve.
## This example uses the CurveArrow class, which is a combination
## of ArrowItem and CurvePoint.
##
## To place a static arrow anywhere in a scene, use ArrowItem.
## To attach other types of item to a curve, use CurvePoint.
To place a static arrow anywhere in a scene, use ArrowItem.
To attach other types of item to a curve, use CurvePoint.
"""
import initExample ## Add path to library (just for examples; you do not need this)
@ -21,6 +22,7 @@ cw = pg.GraphicsLayoutWidget()
w.show()
w.resize(400,600)
w.setCentralWidget(cw)
w.setWindowTitle('pyqtgraph example: Arrow')
p = cw.addPlot(row=0, col=0)
p2 = cw.addPlot(row=1, col=0)

View File

@ -1,21 +1,26 @@
"""
Display a plot and an image with minimal setup.
pg.plot() and pg.image() are indended to be used from an interactive prompt
to allow easy data inspection (but note that PySide unfortunately does not
call the Qt event loop while the interactive prompt is running, in this case
it is necessary to call QApplication.exec_() to make the windows appear).
"""
import initExample ## Add path to library (just for examples; you do not need this)
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
app = QtGui.QApplication([])
data = np.random.normal(size=1000)
pg.plot(data, title="Simplest possible plotting example")
data = np.random.normal(size=(500,500))
pg.show(data, title="Simplest possible image example")
pg.image(data, title="Simplest possible image example")
## 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'):
app.exec_()
pg.QtGui.QApplication.exec_()

View File

@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-
import initExample ## Add path to library (just for examples; you do not need this)
"""
Simple example demonstrating a button which displays a colored rectangle
and allows the user to select a new color by clicking on the button.
"""
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
@ -15,6 +16,7 @@ win = QtGui.QMainWindow()
btn = pg.ColorButton()
win.setCentralWidget(btn)
win.show()
win.setWindowTitle('pyqtgraph example: ColorButton')
def change(btn):
print("change", btn.color())

View File

@ -1,4 +1,10 @@
# -*- coding: utf-8 -*-
"""
ConsoleWidget is used to allow execution of user-supplied python commands
in an application. It also includes a command history and functionality for trapping
and inspecting stack traces.
"""
import initExample ## Add path to library (just for examples; you do not need this)
import pyqtgraph as pg
@ -21,6 +27,7 @@ Go, play.
"""
c = pyqtgraph.console.ConsoleWidget(namespace=namespace, text=text)
c.show()
c.setWindowTitle('pyqtgraph example: ConsoleWidget')
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':

View File

@ -1,4 +1,12 @@
# -*- coding: utf-8 -*-
"""
Demonstrate a simple data-slicing task: given 3D data (displayed at top), select
a 2D plane and interpolate data along that plane to generate a slice image
(displayed at bottom).
"""
## Add path to library (just for examples; you do not need this)
import initExample
@ -12,6 +20,7 @@ app = QtGui.QApplication([])
## Create window with two ImageView widgets
win = QtGui.QMainWindow()
win.resize(800,800)
win.setWindowTitle('pyqtgraph example: DataSlicing')
cw = QtGui.QWidget()
win.setCentralWidget(cw)
l = QtGui.QGridLayout()

View File

@ -4,8 +4,6 @@
Simple use of DataTreeWidget to display a structure of nested dicts, lists, and arrays
"""
import initExample ## Add path to library (just for examples; you do not need this)
import pyqtgraph as pg
@ -26,6 +24,7 @@ d = {
tree = pg.DataTreeWidget(data=d)
tree.show()
tree.setWindowTitle('pyqtgraph example: DataTreeWidget')
tree.resize(600,600)

View File

@ -1,4 +1,10 @@
# -*- coding: utf-8 -*-
"""
Demonstrate ability of ImageItem to be used as a canvas for painting with
the mouse.
"""
import initExample ## Add path to library (just for examples; you do not need this)
@ -12,6 +18,7 @@ app = QtGui.QApplication([])
w = pg.GraphicsView()
w.show()
w.resize(800,800)
w.setWindowTitle('pyqtgraph example: Draw')
view = pg.ViewBox()
w.setCentralItem(view)

View File

@ -21,6 +21,7 @@ top = np.linspace(1.0, 3.0, 10)
bottom = np.linspace(2, 0.5, 10)
plt = pg.plot()
plt.setWindowTitle('pyqtgraph example: ErrorBarItem')
err = pg.ErrorBarItem(x=x, y=y, top=top, bottom=bottom, beam=0.5)
plt.addItem(err)
plt.plot(x, y, symbol='o', pen={'color': 0.8, 'width': 2})

View File

@ -23,6 +23,7 @@ app = QtGui.QApplication([])
## Create main window with grid layout
win = QtGui.QMainWindow()
win.setWindowTitle('pyqtgraph example: Flowchart')
cw = QtGui.QWidget()
win.setCentralWidget(cw)
layout = QtGui.QGridLayout()

View File

@ -18,6 +18,7 @@ app = QtGui.QApplication([])
## Create main window with a grid layout inside
win = QtGui.QMainWindow()
win.setWindowTitle('pyqtgraph example: FlowchartCustomNode')
cw = QtGui.QWidget()
win.setCentralWidget(cw)
layout = QtGui.QGridLayout()

View File

@ -1,4 +1,10 @@
# -*- coding: utf-8 -*-
"""
Use GLImageItem to display image data on rectangular planes.
In this example, the image data is sampled from a volume and the image planes
placed as if they slice through the volume.
"""
## Add path to library (just for examples; you do not need this)
import initExample
@ -12,6 +18,7 @@ app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.opts['distance'] = 200
w.show()
w.setWindowTitle('pyqtgraph example: GLImageItem')
## create volume data set to slice three images from
shape = (100,100,70)

View File

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
## This example uses the isosurface function to convert a scalar field
## (a hydrogen orbital) into a mesh for 3D display.
"""
This example uses the isosurface function to convert a scalar field
(a hydrogen orbital) into a mesh for 3D display.
"""
## Add path to library (just for examples; you do not need this)
import initExample
@ -13,6 +14,7 @@ import pyqtgraph.opengl as gl
app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.show()
w.setWindowTitle('pyqtgraph example: GLIsosurface')
w.setCameraPosition(distance=40)

View File

@ -1,4 +1,8 @@
# -*- coding: utf-8 -*-
"""
Demonstrate use of GLLinePlotItem to draw cross-sections of a surface.
"""
## Add path to library (just for examples; you do not need this)
import initExample
@ -11,6 +15,7 @@ app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.opts['distance'] = 40
w.show()
w.setWindowTitle('pyqtgraph example: GLLinePlotItem')
gx = gl.GLGridItem()
gx.rotate(90, 0, 1, 0)

View File

@ -14,7 +14,7 @@ import pyqtgraph.opengl as gl
app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.show()
w.setWindowTitle('pyqtgraph example: GLMeshItem')
w.setCameraPosition(distance=40)
g = gl.GLGridItem()

View File

@ -1,4 +1,9 @@
# -*- coding: utf-8 -*-
"""
Demonstrates use of GLScatterPlotItem with rapidly-updating plots.
"""
## Add path to library (just for examples; you do not need this)
import initExample
@ -10,6 +15,7 @@ app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.opts['distance'] = 20
w.show()
w.setWindowTitle('pyqtgraph example: GLScatterPlotItem')
g = gl.GLGridItem()
w.addItem(g)

View File

@ -17,6 +17,7 @@ import numpy as np
app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.show()
w.setWindowTitle('pyqtgraph example: GLSurfacePlot')
w.setCameraPosition(distance=50)
## Add a grid to the view

View File

@ -1,4 +1,8 @@
# -*- coding: utf-8 -*-
"""
Very basic 3D graphics example; create a view widget and add a few items.
"""
## Add path to library (just for examples; you do not need this)
import initExample
@ -9,6 +13,7 @@ app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.opts['distance'] = 20
w.show()
w.setWindowTitle('pyqtgraph example: GLViewWidget')
ax = gl.GLAxisItem()
ax.setSize(5,5,5)

View File

@ -1,4 +1,9 @@
# -*- coding: utf-8 -*-
"""
Demonstrates GLVolumeItem for displaying volumetric data.
"""
## Add path to library (just for examples; you do not need this)
import initExample
@ -9,7 +14,7 @@ app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.opts['distance'] = 200
w.show()
w.setWindowTitle('pyqtgraph example: GLVolumeItem')
#b = gl.GLBoxItem()
#w.addItem(b)

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
"""
Demonstration of some of the shader programs included with pyqtgraph.
Demonstration of some of the shader programs included with pyqtgraph that can be
used to affect the appearance of a surface.
"""
@ -15,7 +16,7 @@ import pyqtgraph.opengl as gl
app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.show()
w.setWindowTitle('pyqtgraph example: GL Shaders')
w.setCameraPosition(distance=15, azimuth=-90)
g = gl.GLGridItem()

View File

@ -1,4 +1,9 @@
# -*- coding: utf-8 -*-
"""
Demonstrates the appearance / interactivity of GradientWidget
(without actually doing anything useful with it)
"""
import initExample ## Add path to library (just for examples; you do not need this)
import pyqtgraph as pg
@ -10,6 +15,7 @@ import numpy as np
app = QtGui.QApplication([])
w = QtGui.QMainWindow()
w.show()
w.setWindowTitle('pyqtgraph example: GradientWidget')
w.resize(400,400)
cw = QtGui.QWidget()
w.setCentralWidget(cw)

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""
Simple example of GridItem use.
Simple example of GraphItem use.
"""
@ -11,6 +11,7 @@ from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
w = pg.GraphicsWindow()
w.setWindowTitle('pyqtgraph example: GraphItem')
v = w.addViewBox()
v.setAspectLocked()

View File

@ -1,3 +1,10 @@
"""
Demonstrate the use of layouts to control placement of multiple plots / views /
labels
"""
## Add path to library (just for examples; you do not need this)
import initExample
@ -10,6 +17,7 @@ view = pg.GraphicsView()
l = pg.GraphicsLayout(border=(100,100,100))
view.setCentralItem(l)
view.show()
view.setWindowTitle('pyqtgraph example: GraphicsLayout')
view.resize(800,600)
## Title at top

View File

@ -1,4 +1,8 @@
# -*- coding: utf-8 -*-
"""
Use a HistogramLUTWidget to control the contrast / coloration of an image.
"""
## Add path to library (just for examples; you do not need this)
import initExample
@ -12,6 +16,7 @@ app = QtGui.QApplication([])
win = QtGui.QMainWindow()
win.resize(800,600)
win.show()
win.setWindowTitle('pyqtgraph example: Histogram LUT')
cw = QtGui.QWidget()
win.setCentralWidget(cw)

View File

@ -1,4 +1,8 @@
# -*- coding: utf-8 -*-
"""
Demonstrates very basic use of ImageItem to display image data inside a ViewBox.
"""
## Add path to library (just for examples; you do not need this)
import initExample
@ -10,19 +14,17 @@ import pyqtgraph.ptime as ptime
app = QtGui.QApplication([])
## Create window with GraphicsView widget
view = pg.GraphicsView()
view.show() ## show view alone in its own window
## Allow mouse scale/pan. Normally we use a ViewBox for this, but
## for simple examples this is easier.
view.enableMouse()
win = pg.GraphicsLayoutWidget()
win.show() ## show widget alone in its own window
win.setWindowTitle('pyqtgraph example: ImageItem')
view = win.addViewBox()
## lock the aspect ratio so pixels are always square
view.setAspectLocked(True)
## Create image item
img = pg.ImageItem(border='w')
view.scene().addItem(img)
view.addItem(img)
## Set initial view bounds
view.setRange(QtCore.QRectF(0, 0, 600, 600))

View File

@ -26,6 +26,7 @@ win.resize(800,800)
imv = pg.ImageView()
win.setCentralWidget(imv)
win.show()
win.setWindowTitle('pyqtgraph example: ImageView')
## Create random 3D data set with noisy signals
img = scipy.ndimage.gaussian_filter(np.random.normal(size=(200, 200)), (5, 5)) * 20 + 100

View File

@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
"""
JoystickButton is a button with x/y values. When the button is depressed and the mouse dragged, the x/y values change to follow the mouse.
When the mouse button is released, the x/y values change to 0,0 (rather like litting go of the joystick).
JoystickButton is a button with x/y values. When the button is depressed and the
mouse dragged, the x/y values change to follow the mouse.
When the mouse button is released, the x/y values change to 0,0 (rather like
letting go of the joystick).
"""
import initExample ## Add path to library (just for examples; you do not need this)
@ -13,6 +15,7 @@ import pyqtgraph as pg
app = QtGui.QApplication([])
mw = QtGui.QMainWindow()
mw.resize(300,50)
mw.setWindowTitle('pyqtgraph example: JoystickButton')
cw = QtGui.QWidget()
mw.setCentralWidget(cw)
layout = QtGui.QGridLayout()

View File

@ -1,11 +1,15 @@
# -*- coding: utf-8 -*-
"""
Demonstrates basic use of LegendItem
"""
import initExample ## Add path to library (just for examples; you do not need this)
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
plt = pg.plot()
plt.setWindowTitle('pyqtgraph example: Legend')
plt.addLegend()
#l = pg.LegendItem((100,60), offset=(70,30)) # args are (size, offset)
#l.setParentItem(plt.graphicsItem()) # Note we do NOT call plt.addItem in this case

View File

@ -1,9 +1,7 @@
# -*- coding: utf-8 -*-
## 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.
"""
Simple logarithmic plotting test
"""
import initExample ## Add path to library (just for examples; you do not need this)
@ -12,14 +10,11 @@ from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
#QtGui.QApplication.setGraphicsSystem('raster')
app = QtGui.QApplication([])
#mw = QtGui.QMainWindow()
#mw.resize(800,800)
win = pg.GraphicsWindow(title="Basic plotting examples")
win.resize(1000,600)
win.setWindowTitle('pyqtgraph example: LogPlotTest')
p5 = win.addPlot(title="Scatter plot, axis labels, log scale")

View File

@ -1,5 +1,9 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Test the speed of rapidly updating multiple plot curves
"""
## Add path to library (just for examples; you do not need this)
import initExample
@ -14,6 +18,7 @@ app = QtGui.QApplication([])
#mw.resize(800,800)
p = pg.plot()
p.setWindowTitle('pyqtgraph example: MultiPlotSpeedTest')
#p.setRange(QtCore.QRectF(0, -10, 5000, 20))
p.setLabel('bottom', 'Index', units='B')

View File

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
## This example demonstrates the different auto-ranging capabilities of ViewBoxes
"""
This example demonstrates the different auto-ranging capabilities of ViewBoxes
"""
import initExample ## Add path to library (just for examples; you do not need this)
@ -17,7 +18,7 @@ app = QtGui.QApplication([])
win = pg.GraphicsWindow(title="Plot auto-range examples")
win.resize(800,600)
win.setWindowTitle('pyqtgraph example: PlotAutoRange')
d = np.random.normal(size=100)
d[50:54] += 10

View File

@ -1,5 +1,9 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Update a simple plot as rapidly as possible to measure speed.
"""
## Add path to library (just for examples; you do not need this)
import initExample
@ -8,12 +12,10 @@ from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
from pyqtgraph.ptime import time
#QtGui.QApplication.setGraphicsSystem('raster')
app = QtGui.QApplication([])
#mw = QtGui.QMainWindow()
#mw.resize(800,800)
p = pg.plot()
p.setWindowTitle('pyqtgraph example: PlotSpeedTest')
p.setRange(QtCore.QRectF(0, -10, 5000, 20))
p.setLabel('bottom', 'Index', units='B')
curve = p.plot()

View File

@ -1,4 +1,10 @@
# -*- coding: utf-8 -*-
"""
Demonstrates use of PlotWidget class. This is little more than a
GraphicsView with a PlotItem placed in its center.
"""
import initExample ## Add path to library (just for examples; you do not need this)
@ -9,6 +15,7 @@ import pyqtgraph as pg
#QtGui.QApplication.setGraphicsSystem('raster')
app = QtGui.QApplication([])
mw = QtGui.QMainWindow()
mw.setWindowTitle('pyqtgraph example: PlotWidget')
mw.resize(800,800)
cw = QtGui.QWidget()
mw.setCentralWidget(cw)

View File

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
## 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.
"""
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.
"""
import initExample ## Add path to library (just for examples; you do not need this)
@ -19,6 +19,7 @@ app = QtGui.QApplication([])
win = pg.GraphicsWindow(title="Basic plotting examples")
win.resize(1000,600)
win.setWindowTitle('pyqtgraph example: Plotting')

View File

@ -1,4 +1,10 @@
# -*- coding: utf-8 -*-
"""
Demonstrates a variety of uses for ROI. This class provides a user-adjustable
region of interest marker. It is possible to customize the layout and
function of the scale/rotate handles in very flexible ways.
"""
import initExample ## Add path to library (just for examples; you do not need this)
import pyqtgraph as pg
@ -22,6 +28,7 @@ arr += np.random.normal(size=(100,100))
## create GUI
app = QtGui.QApplication([])
w = pg.GraphicsWindow(size=(800,800), border=True)
w.setWindowTitle('pyqtgraph example: ROI Examples')
text = """Data Selection From Image.<br>\n
Drag an ROI or its handles to update the selected image.<br>

View File

@ -1,18 +1,25 @@
# -*- coding: utf-8 -*-
"""
Very simple example demonstrating RemoteGraphicsView
"""
import initExample ## Add path to library (just for examples; you do not need this)
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
from pyqtgraph.widgets.RemoteGraphicsView import RemoteGraphicsView
app = pg.mkQApp()
v = pg.RemoteGraphicsView()
v = RemoteGraphicsView()
v.show()
v.setWindowTitle('pyqtgraph example: RemoteGraphicsView')
## v.pg is a proxy to the remote process' pyqtgraph module. All attribute
## requests and function calls made with this object are forwarded to the
## remote process and executed there.
plt = v.pg.PlotItem()
v.setCentralItem(plt)
plt.plot([1,4,2,3,6,2,3,4,2,3], pen='g')
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys

View File

@ -22,6 +22,7 @@ app = pg.mkQApp()
view = pg.widgets.RemoteGraphicsView.RemoteGraphicsView()
pg.setConfigOptions(antialias=True) ## this will be expensive for the local plot
view.pg.setConfigOptions(antialias=True) ## prettier plots at no cost to the main process!
view.setWindowTitle('pyqtgraph example: RemoteSpeedTest')
label = QtGui.QLabel()
rcheck = QtGui.QCheckBox('plot remote')

View File

@ -1,4 +1,10 @@
# -*- coding: utf-8 -*-
"""
Example demonstrating a variety of scatter plot features.
"""
## Add path to library (just for examples; you do not need this)
import initExample
@ -12,6 +18,7 @@ mw.resize(800,800)
view = pg.GraphicsLayoutWidget() ## GraphicsView with GraphicsLayout inserted by default
mw.setCentralWidget(view)
mw.show()
mw.setWindowTitle('pyqtgraph example: ScatterPlot')
## create four areas to add plots
w1 = view.addPlot()

View File

@ -1,5 +1,13 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
For testing rapid updates of ScatterPlotItem under various conditions.
(Scatter plots are still rather slow to draw; expect about 20fps)
"""
## Add path to library (just for examples; you do not need this)
import initExample
@ -18,6 +26,7 @@ else:
from ScatterPlotSpeedTestTemplate_pyqt import Ui_Form
win = QtGui.QWidget()
win.setWindowTitle('pyqtgraph example: ScatterPlotSpeedTest')
ui = Ui_Form()
ui.setupUi(win)
win.show()

View File

@ -1,4 +1,13 @@
# -*- coding: utf-8 -*-
"""
This example demonstrates the SpinBox widget, which is an extension of
QDoubleSpinBox providing some advanced features:
* SI-prefixed units
* Non-linear stepping modes
* Bounded/unbounded values
"""
import initExample ## Add path to library (just for examples; you do not need this)
import pyqtgraph as pg
@ -20,6 +29,7 @@ spins = [
win = QtGui.QMainWindow()
win.setWindowTitle('pyqtgraph example: SpinBox')
cw = QtGui.QWidget()
layout = QtGui.QGridLayout()
cw.setLayout(layout)

View File

@ -1,4 +1,8 @@
# -*- coding: utf-8 -*-
"""
Simple demonstration of TreeWidget, which is an extension of QTreeWidget
that allows widgets to be added and dragged within the tree more easily.
"""
import initExample ## Add path to library (just for examples; you do not need this)
import pyqtgraph as pg
@ -11,6 +15,7 @@ app = QtGui.QApplication([])
w = pg.TreeWidget()
w.setColumnCount(2)
w.show()
w.setWindowTitle('pyqtgraph example: TreeWidget')
i1 = QtGui.QTreeWidgetItem(["Item 1"])
i11 = QtGui.QTreeWidgetItem(["Item 1.1"])

View File

@ -29,6 +29,7 @@ app = QtGui.QApplication([])
#mw.resize(800,800)
win = QtGui.QMainWindow()
win.setWindowTitle('pyqtgraph example: VideoSpeedTest')
ui = VideoTemplate.Ui_MainWindow()
ui.setupUi(win)
win.show()

View File

@ -1,5 +1,14 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
ViewBox is the general-purpose graphical container that allows the user to
zoom / pan to inspect any area of a 2D coordinate system.
This unimaginative example demonstrates the constrution of a ViewBox-based
plot area with axes, very similar to the way PlotItem is built.
"""
## Add path to library (just for examples; you do not need this)
import initExample
@ -12,25 +21,17 @@ import pyqtgraph as pg
app = QtGui.QApplication([])
mw = QtGui.QMainWindow()
#cw = QtGui.QWidget()
#vl = QtGui.QVBoxLayout()
#cw.setLayout(vl)
#mw.setCentralWidget(cw)
mw.setWindowTitle('pyqtgraph example: ViewBox')
mw.show()
mw.resize(800, 600)
gv = pg.GraphicsView()
mw.setCentralWidget(gv)
#gv.enableMouse(False) ## Mouse interaction will be handled by the ViewBox
l = QtGui.QGraphicsGridLayout()
l.setHorizontalSpacing(0)
l.setVerticalSpacing(0)
#vl.addWidget(gv)
vb = pg.ViewBox()
#grid = pg.GridItem()
#vb.addItem(grid)
p1 = pg.PlotDataItem()
vb.addItem(p1)

View File

@ -22,6 +22,7 @@ examples = OrderedDict([
('Dock widgets', 'dockarea.py'),
('Console', 'ConsoleWidget.py'),
('Histograms', 'histogram.py'),
('Auto-range', 'PlotAutoRange.py'),
('Remote Plotting', 'RemoteSpeedTest.py'),
('GraphicsItems', OrderedDict([
('Scatter Plot', 'ScatterPlot.py'),
@ -38,6 +39,7 @@ examples = OrderedDict([
('Linked Views', 'linkedViews.py'),
('Arrow', 'Arrow.py'),
('ViewBox', 'ViewBox.py'),
('Custom Graphics', 'customGraphicsItem.py'),
])),
('Benchmarks', OrderedDict([
('Video speed test', 'VideoSpeedTest.py'),
@ -58,6 +60,7 @@ examples = OrderedDict([
('PlotWidget', 'PlotWidget.py'),
('SpinBox', 'SpinBox.py'),
('ConsoleWidget', 'ConsoleWidget.py'),
('Histogram / lookup table', 'HistogramLUT.py'),
('TreeWidget', 'TreeWidget.py'),
('DataTreeWidget', 'DataTreeWidget.py'),
('GradientWidget', 'GradientWidget.py'),
@ -68,7 +71,7 @@ examples = OrderedDict([
('JoystickButton', 'JoystickButton.py'),
])),
('GraphicsScene', 'GraphicsScene.py'),
#('GraphicsScene', 'GraphicsScene.py'),
('Flowcharts', 'Flowchart.py'),
('Custom Flowchart Nodes', 'FlowchartCustomNode.py'),
#('Canvas', '../canvas'),

View File

@ -1,3 +1,10 @@
"""
Demonstrates some customized mouse interaction by drawing a crosshair that follows
the mouse.
"""
import initExample ## Add path to library (just for examples; you do not need this)
import numpy as np
import scipy.ndimage as ndi
@ -5,9 +12,10 @@ import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore
from pyqtgraph.Point import Point
#genearte layout
#generate layout
app = QtGui.QApplication([])
win = pg.GraphicsWindow()
win.setWindowTitle('pyqtgraph example: crosshair')
label = pg.LabelItem(justify='right')
win.addItem(label)
p1 = win.addPlot(row=1, col=0)

View File

@ -1,6 +1,15 @@
"""
Demonstrate creation of a custom graphic (a candlestick plot)
"""
import initExample ## Add path to library (just for examples; you do not need this)
import pyqtgraph as pg
from pyqtgraph import QtCore, QtGui
## Create a subclass of GraphicsObject.
## The only required methods are paint() and boundingRect()
## (see QGraphicsItem documentation)
class CandlestickItem(pg.GraphicsObject):
def __init__(self, data):
pg.GraphicsObject.__init__(self)
@ -8,6 +17,8 @@ class CandlestickItem(pg.GraphicsObject):
self.generatePicture()
def generatePicture(self):
## pre-computing a QPicture object allows paint() to run much more quickly,
## rather than re-drawing the shapes every time.
self.picture = QtGui.QPicture()
p = QtGui.QPainter(self.picture)
p.setPen(pg.mkPen('w'))
@ -25,6 +36,9 @@ class CandlestickItem(pg.GraphicsObject):
p.drawPicture(0, 0, self.picture)
def boundingRect(self):
## boundingRect _must_ indicate the entire area that will be drawn on
## or else we will get artifacts and possibly crashing.
## (in this case, QPicture does all the work of computing the bouning rect for us)
return QtCore.QRectF(self.picture.boundingRect())
data = [ ## fields are (time, open, close, min, max).
@ -38,5 +52,10 @@ data = [ ## fields are (time, open, close, min, max).
item = CandlestickItem(data)
plt = pg.plot()
plt.addItem(item)
plt.setWindowTitle('pyqtgraph example: customGraphicsItem')
QtGui.QApplication.exec_()
## 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_()

View File

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
##
## This example demonstrates the creation of a plot with a customized
## AxisItem and ViewBox.
##
"""
This example demonstrates the creation of a plot with a customized
AxisItem and ViewBox.
"""
import initExample ## Add path to library (just for examples; you do not need this)
@ -72,6 +72,7 @@ pw = pg.PlotWidget(viewBox=vb, axisItems={'bottom': axis}, enableMenu=False, tit
dates = np.arange(8) * (3600*24*356)
pw.plot(x=dates, y=[1,6,2,4,3,5,6,8], symbol='o')
pw.show()
pw.setWindowTitle('pyqtgraph example: customPlot')
r = pg.PolyLineROI([(0,0), (10, 10)])
pw.addItem(r)

View File

@ -29,6 +29,7 @@ win = QtGui.QMainWindow()
area = DockArea()
win.setCentralWidget(area)
win.resize(1000,500)
win.setWindowTitle('pyqtgraph example: dockarea')
## Create docks, place them into the window one at a time.
## Note that size arguments are only a suggestion; docks will still have to

View File

@ -12,13 +12,14 @@ import numpy as np
win = pg.GraphicsWindow()
win.resize(800,350)
win.setWindowTitle('pyqtgraph example: Histogram')
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
## compute standard histogram
y,x = np.histogram(vals, bins=np.linspace(-3, 8, 40))
## notice that len(x) == len(y)+1

View File

@ -22,6 +22,7 @@ data = ndi.gaussian_filter(data, (10, 10, 10))[frames/2:frames + frames/2]
data[:, 15:16, 15:17] += 1
win = pg.GraphicsWindow()
win.setWindowTitle('pyqtgraph example: Isocurve')
vb = win.addViewBox()
img = pg.ImageItem(data[0])
vb.addItem(img)

View File

@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
## This example demonstrates the ability to link the axes of views together
## Views can be linked manually using the context menu, but only if they are given names.
"""
This example demonstrates the ability to link the axes of views together
Views can be linked manually using the context menu, but only if they are given
names.
"""
import initExample ## Add path to library (just for examples; you do not need this)
@ -19,7 +20,7 @@ app = QtGui.QApplication([])
x = np.linspace(-50, 50, 1000)
y = np.sin(x) / x
win = pg.GraphicsWindow(title="View Linking Examples")
win = pg.GraphicsWindow(title="pyqtgraph example: Linked Views")
win.resize(800,600)
win.addLabel("Linked Views", colspan=2)

View File

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
"""
Test programmatically setting log transformation modes.
"""
import initExample ## Add path to library (just for examples; you do not need this)
import numpy as np
@ -10,6 +12,7 @@ import pyqtgraph as pg
app = QtGui.QApplication([])
w = pg.GraphicsWindow()
w.setWindowTitle('pyqtgraph example: logAxis')
p1 = w.addPlot(0,0, title="X Semilog")
p2 = w.addPlot(1,0, title="Y Semilog")
p3 = w.addPlot(2,0, title="XY Log")

View File

@ -39,7 +39,7 @@ def plot():
#plt.addItem(item)
dt = pg.ptime.time() - start
print "Create plots took: %0.3fms" % (dt*1000)
print("Create plots took: %0.3fms" % (dt*1000))
## Plot and clear 5 times, printing the time it took
for i in range(5):
@ -72,7 +72,7 @@ def fastPlot():
plt.addItem(item)
dt = pg.ptime.time() - start
print "Create plots took: %0.3fms" % (dt*1000)
print("Create plots took: %0.3fms" % (dt*1000))
## Plot and clear 5 times, printing the time it took
@ -82,7 +82,7 @@ if hasattr(pg, 'arrayToQPath'):
fastPlot()
app.processEvents()
else:
print "Skipping fast tests--arrayToQPath function is missing."
print("Skipping fast tests--arrayToQPath function is missing.")
plt.autoRange()

View File

@ -140,6 +140,7 @@ p.param('Save/Restore functionality', 'Restore State').sigActivated.connect(rest
t = ParameterTree()
t.setParameters(p, showTop=False)
t.show()
t.setWindowTitle('pyqtgraph example: Parameter Tree')
t.resize(400,800)
t2 = ParameterTree()
t2.setParameters(p, showTop=False)

View File

@ -1,10 +1,18 @@
# -*- coding: utf-8 -*-
"""
Description of example
"""
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.setWindowTitle('pyqtgraph example: ____')
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys

View File

@ -1,6 +1,12 @@
# -*- coding: utf-8 -*-
## This example shows how to insert text into a scene using QTextItem
"""
This example shows how to insert text into a scene using TextItem. This class
is for displaying text that is anchored to a particular location in the data
coordinate system, but which is always displayed unscaled.
For text that scales with the data, use QTextItem.
For text that can be placed in a layout, use LabelItem.
"""
import initExample ## Add path to library (just for examples; you do not need this)
@ -13,6 +19,7 @@ x = np.linspace(-20, 20, 1000)
y = np.sin(x) / x
plot = pg.plot() ## create an empty plot widget
plot.setYRange(-1, 2)
plot.setWindowTitle('pyqtgraph example: text')
curve = plot.plot(x,y) ## add a single curve
## Create text object, use HTML tags to specify color/size

View File

@ -10,7 +10,7 @@ as it can be converted to/from a string using repr and eval.
"""
import re, os, sys
from pgcollections import OrderedDict
from .pgcollections import OrderedDict
GLOBAL_PATH = None # so not thread safe.
from . import units
from .python2_3 import asUnicode

View File

@ -90,7 +90,7 @@
<customwidget>
<class>FlowchartGraphicsView</class>
<extends>QGraphicsView</extends>
<header>FlowchartGraphicsView</header>
<header>pyqtgraph.flowchart.FlowchartGraphicsView</header>
</customwidget>
</customwidgets>
<resources/>

View File

@ -2,8 +2,8 @@
# Form implementation generated from reading ui file './flowchart/FlowchartTemplate.ui'
#
# Created: Sun Sep 9 14:41:29 2012
# by: PyQt4 UI code generator 4.9.1
# Created: Sun Feb 24 19:47:29 2013
# by: PyQt4 UI code generator 4.9.3
#
# WARNING! All changes made in this file will be lost!
@ -56,4 +56,4 @@ class Ui_Form(object):
Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
from pyqtgraph.widgets.DataTreeWidget import DataTreeWidget
from FlowchartGraphicsView import FlowchartGraphicsView
from pyqtgraph.flowchart.FlowchartGraphicsView import FlowchartGraphicsView

View File

@ -2,8 +2,8 @@
# Form implementation generated from reading ui file './flowchart/FlowchartTemplate.ui'
#
# Created: Sun Sep 9 14:41:30 2012
# by: pyside-uic 0.2.13 running on PySide 1.1.0
# Created: Sun Feb 24 19:47:30 2013
# by: pyside-uic 0.2.13 running on PySide 1.1.1
#
# WARNING! All changes made in this file will be lost!
@ -51,4 +51,4 @@ class Ui_Form(object):
Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
from pyqtgraph.widgets.DataTreeWidget import DataTreeWidget
from FlowchartGraphicsView import FlowchartGraphicsView
from pyqtgraph.flowchart.FlowchartGraphicsView import FlowchartGraphicsView

View File

@ -451,7 +451,7 @@ class ViewBox(GraphicsWidget):
if item is None:
bounds = self.childrenBoundingRect(items=items)
else:
print "Warning: ViewBox.autoRange(item=__) is deprecated. Use 'items' argument instead."
print("Warning: ViewBox.autoRange(item=__) is deprecated. Use 'items' argument instead.")
bounds = self.mapFromItemToView(item, item.boundingRect()).boundingRect()
if bounds is not None: