Commit 03683a5e authored by Luke Campagnola's avatar Luke Campagnola
Browse files

Bugfixes:

  - ArrowItem auto range now works correctly
  - Dock drag/drop fixed on PySide
  - Made padding behavior consistent across ViewBox methods
  - Fixed MeshData / python2.6 incompatibility
  - Fixed ScatterPlotItem.setSize and .setPointData
  - Workaround for PySide bug; GradientEditor fixed
  - Prefer initially selecting PlotItem rather then ViewBox when exporting
  - Fixed python3 import error with flowcharts

Cleaned up examples, made code editable from example loader
Minor documentation updates
parents 2e79185d 4cf9ef70
...@@ -17,7 +17,7 @@ Pyqtgraph makes it very easy to visualize data from the command line. Observe:: ...@@ -17,7 +17,7 @@ Pyqtgraph makes it very easy to visualize data from the command line. Observe::
import pyqtgraph as pg import pyqtgraph as pg
pg.plot(data) # data can be a list of values or a numpy array pg.plot(data) # data can be a list of values or a numpy array
The example above would open a window displaying a line plot of the data given. The call to :func:`pg.plot <pyqtgraph.plot>` returns a handle to the :class:`plot widget <pyqtgraph.PlotWidget>` that is created, allowing more data to be added to the same window. The example above would open a window displaying a line plot of the data given. The call to :func:`pg.plot <pyqtgraph.plot>` returns a handle to the :class:`plot widget <pyqtgraph.PlotWidget>` that is created, allowing more data to be added to the same window. **Note:** interactive plotting from the python prompt is only available with PyQt; PySide does not run the Qt event loop while the interactive prompt is running. If you wish to use pyqtgraph interactively with PySide, see the 'console' :ref:`example <examples>`.
Further examples:: Further examples::
......
...@@ -66,6 +66,12 @@ Signals, Slots, and Events ...@@ -66,6 +66,12 @@ Signals, Slots, and Events
[ to be continued.. please post a request on the pyqtgraph forum if you'd like to read more ] [ to be continued.. please post a request on the pyqtgraph forum if you'd like to read more ]
Qt detects and reacts to user interaction by executing its *event loop*.
- what happens in the event loop?
- when do I need to use QApplication.exec_() ?
- what control do I have over event loop execution? (QApplication.processEvents)
GraphicsView and GraphicsItems GraphicsView and GraphicsItems
------------------------------ ------------------------------
...@@ -79,8 +85,8 @@ Mouse and Keyboard Input ...@@ -79,8 +85,8 @@ Mouse and Keyboard Input
------------------------ ------------------------
QTimer, the Event Loop, and Multi-Threading QTimer, Multi-Threading
------------------------------------------- -----------------------
Multi-threading vs Multi-processing in Qt Multi-threading vs Multi-processing in Qt
......
# -*- coding: utf-8 -*- # -*- 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. To place a static arrow anywhere in a scene, use ArrowItem.
## This example uses the CurveArrow class, which is a combination To attach other types of item to a curve, use CurvePoint.
## 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.
import initExample ## Add path to library (just for examples; you do not need this) import initExample ## Add path to library (just for examples; you do not need this)
...@@ -21,6 +22,7 @@ cw = pg.GraphicsLayoutWidget() ...@@ -21,6 +22,7 @@ cw = pg.GraphicsLayoutWidget()
w.show() w.show()
w.resize(400,600) w.resize(400,600)
w.setCentralWidget(cw) w.setCentralWidget(cw)
w.setWindowTitle('pyqtgraph example: Arrow')
p = cw.addPlot(row=0, col=0) p = cw.addPlot(row=0, col=0)
p2 = cw.addPlot(row=1, col=0) p2 = cw.addPlot(row=1, col=0)
......
"""
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) 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 numpy as np
import pyqtgraph as pg import pyqtgraph as pg
app = QtGui.QApplication([])
data = np.random.normal(size=1000) data = np.random.normal(size=1000)
pg.plot(data, title="Simplest possible plotting example") pg.plot(data, title="Simplest possible plotting example")
data = np.random.normal(size=(500,500)) 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. ## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__': if __name__ == '__main__':
import sys import sys
if sys.flags.interactive != 1 or not hasattr(QtCore, 'PYQT_VERSION'): if sys.flags.interactive != 1 or not hasattr(QtCore, 'PYQT_VERSION'):
app.exec_() pg.QtGui.QApplication.exec_()
# -*- coding: utf-8 -*- # -*- 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 Simple example demonstrating a button which displays a colored rectangle
and allows the user to select a new color by clicking on the button. 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 import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui from pyqtgraph.Qt import QtCore, QtGui
import numpy as np import numpy as np
...@@ -15,6 +16,7 @@ win = QtGui.QMainWindow() ...@@ -15,6 +16,7 @@ win = QtGui.QMainWindow()
btn = pg.ColorButton() btn = pg.ColorButton()
win.setCentralWidget(btn) win.setCentralWidget(btn)
win.show() win.show()
win.setWindowTitle('pyqtgraph example: ColorButton')
def change(btn): def change(btn):
print("change", btn.color()) print("change", btn.color())
......
# -*- coding: utf-8 -*- # -*- 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 initExample ## Add path to library (just for examples; you do not need this)
import pyqtgraph as pg import pyqtgraph as pg
...@@ -21,6 +27,7 @@ Go, play. ...@@ -21,6 +27,7 @@ Go, play.
""" """
c = pyqtgraph.console.ConsoleWidget(namespace=namespace, text=text) c = pyqtgraph.console.ConsoleWidget(namespace=namespace, text=text)
c.show() c.show()
c.setWindowTitle('pyqtgraph example: ConsoleWidget')
## Start Qt event loop unless running in interactive mode or using pyside. ## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__': if __name__ == '__main__':
......
# -*- coding: utf-8 -*- # -*- 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) ## Add path to library (just for examples; you do not need this)
import initExample import initExample
...@@ -12,6 +20,7 @@ app = QtGui.QApplication([]) ...@@ -12,6 +20,7 @@ app = QtGui.QApplication([])
## Create window with two ImageView widgets ## Create window with two ImageView widgets
win = QtGui.QMainWindow() win = QtGui.QMainWindow()
win.resize(800,800) win.resize(800,800)
win.setWindowTitle('pyqtgraph example: DataSlicing')
cw = QtGui.QWidget() cw = QtGui.QWidget()
win.setCentralWidget(cw) win.setCentralWidget(cw)
l = QtGui.QGridLayout() l = QtGui.QGridLayout()
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
Simple use of DataTreeWidget to display a structure of nested dicts, lists, and arrays 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 initExample ## Add path to library (just for examples; you do not need this)
import pyqtgraph as pg import pyqtgraph as pg
...@@ -26,6 +24,7 @@ d = { ...@@ -26,6 +24,7 @@ d = {
tree = pg.DataTreeWidget(data=d) tree = pg.DataTreeWidget(data=d)
tree.show() tree.show()
tree.setWindowTitle('pyqtgraph example: DataTreeWidget')
tree.resize(600,600) tree.resize(600,600)
......
# -*- coding: utf-8 -*- # -*- 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) import initExample ## Add path to library (just for examples; you do not need this)
...@@ -12,6 +18,7 @@ app = QtGui.QApplication([]) ...@@ -12,6 +18,7 @@ app = QtGui.QApplication([])
w = pg.GraphicsView() w = pg.GraphicsView()
w.show() w.show()
w.resize(800,800) w.resize(800,800)
w.setWindowTitle('pyqtgraph example: Draw')
view = pg.ViewBox() view = pg.ViewBox()
w.setCentralItem(view) w.setCentralItem(view)
......
...@@ -21,6 +21,7 @@ top = np.linspace(1.0, 3.0, 10) ...@@ -21,6 +21,7 @@ top = np.linspace(1.0, 3.0, 10)
bottom = np.linspace(2, 0.5, 10) bottom = np.linspace(2, 0.5, 10)
plt = pg.plot() plt = pg.plot()
plt.setWindowTitle('pyqtgraph example: ErrorBarItem')
err = pg.ErrorBarItem(x=x, y=y, top=top, bottom=bottom, beam=0.5) err = pg.ErrorBarItem(x=x, y=y, top=top, bottom=bottom, beam=0.5)
plt.addItem(err) plt.addItem(err)
plt.plot(x, y, symbol='o', pen={'color': 0.8, 'width': 2}) plt.plot(x, y, symbol='o', pen={'color': 0.8, 'width': 2})
......
...@@ -23,6 +23,7 @@ app = QtGui.QApplication([]) ...@@ -23,6 +23,7 @@ app = QtGui.QApplication([])
## Create main window with grid layout ## Create main window with grid layout
win = QtGui.QMainWindow() win = QtGui.QMainWindow()
win.setWindowTitle('pyqtgraph example: Flowchart')
cw = QtGui.QWidget() cw = QtGui.QWidget()
win.setCentralWidget(cw) win.setCentralWidget(cw)
layout = QtGui.QGridLayout() layout = QtGui.QGridLayout()
......
...@@ -18,6 +18,7 @@ app = QtGui.QApplication([]) ...@@ -18,6 +18,7 @@ app = QtGui.QApplication([])
## Create main window with a grid layout inside ## Create main window with a grid layout inside
win = QtGui.QMainWindow() win = QtGui.QMainWindow()
win.setWindowTitle('pyqtgraph example: FlowchartCustomNode')
cw = QtGui.QWidget() cw = QtGui.QWidget()
win.setCentralWidget(cw) win.setCentralWidget(cw)
layout = QtGui.QGridLayout() layout = QtGui.QGridLayout()
......
# -*- coding: utf-8 -*- # -*- 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) ## Add path to library (just for examples; you do not need this)
import initExample import initExample
...@@ -12,6 +18,7 @@ app = QtGui.QApplication([]) ...@@ -12,6 +18,7 @@ app = QtGui.QApplication([])
w = gl.GLViewWidget() w = gl.GLViewWidget()
w.opts['distance'] = 200 w.opts['distance'] = 200
w.show() w.show()
w.setWindowTitle('pyqtgraph example: GLImageItem')
## create volume data set to slice three images from ## create volume data set to slice three images from
shape = (100,100,70) shape = (100,100,70)
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""
## This example uses the isosurface function to convert a scalar field This example uses the isosurface function to convert a scalar field
## (a hydrogen orbital) into a mesh for 3D display. (a hydrogen orbital) into a mesh for 3D display.
"""
## Add path to library (just for examples; you do not need this) ## Add path to library (just for examples; you do not need this)
import initExample import initExample
...@@ -13,6 +14,7 @@ import pyqtgraph.opengl as gl ...@@ -13,6 +14,7 @@ import pyqtgraph.opengl as gl
app = QtGui.QApplication([]) app = QtGui.QApplication([])
w = gl.GLViewWidget() w = gl.GLViewWidget()
w.show() w.show()
w.setWindowTitle('pyqtgraph example: GLIsosurface')
w.setCameraPosition(distance=40) w.setCameraPosition(distance=40)
......
# -*- coding: utf-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) ## Add path to library (just for examples; you do not need this)
import initExample import initExample
...@@ -11,6 +15,7 @@ app = QtGui.QApplication([]) ...@@ -11,6 +15,7 @@ app = QtGui.QApplication([])
w = gl.GLViewWidget() w = gl.GLViewWidget()
w.opts['distance'] = 40 w.opts['distance'] = 40
w.show() w.show()
w.setWindowTitle('pyqtgraph example: GLLinePlotItem')
gx = gl.GLGridItem() gx = gl.GLGridItem()
gx.rotate(90, 0, 1, 0) gx.rotate(90, 0, 1, 0)
......
...@@ -14,7 +14,7 @@ import pyqtgraph.opengl as gl ...@@ -14,7 +14,7 @@ import pyqtgraph.opengl as gl
app = QtGui.QApplication([]) app = QtGui.QApplication([])
w = gl.GLViewWidget() w = gl.GLViewWidget()
w.show() w.show()
w.setWindowTitle('pyqtgraph example: GLMeshItem')
w.setCameraPosition(distance=40) w.setCameraPosition(distance=40)
g = gl.GLGridItem() g = gl.GLGridItem()
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""
Demonstrates use of GLScatterPlotItem with rapidly-updating plots.
"""
## Add path to library (just for examples; you do not need this) ## Add path to library (just for examples; you do not need this)
import initExample import initExample
...@@ -10,6 +15,7 @@ app = QtGui.QApplication([]) ...@@ -10,6 +15,7 @@ app = QtGui.QApplication([])
w = gl.GLViewWidget() w = gl.GLViewWidget()
w.opts['distance'] = 20 w.opts['distance'] = 20
w.show() w.show()
w.setWindowTitle('pyqtgraph example: GLScatterPlotItem')
g = gl.GLGridItem() g = gl.GLGridItem()
w.addItem(g) w.addItem(g)
......
...@@ -17,6 +17,7 @@ import numpy as np ...@@ -17,6 +17,7 @@ import numpy as np
app = QtGui.QApplication([]) app = QtGui.QApplication([])
w = gl.GLViewWidget() w = gl.GLViewWidget()
w.show() w.show()
w.setWindowTitle('pyqtgraph example: GLSurfacePlot')
w.setCameraPosition(distance=50) w.setCameraPosition(distance=50)
## Add a grid to the view ## Add a grid to the view
......
# -*- coding: utf-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) ## Add path to library (just for examples; you do not need this)
import initExample import initExample
...@@ -9,6 +13,7 @@ app = QtGui.QApplication([]) ...@@ -9,6 +13,7 @@ app = QtGui.QApplication([])
w = gl.GLViewWidget() w = gl.GLViewWidget()
w.opts['distance'] = 20 w.opts['distance'] = 20
w.show() w.show()
w.setWindowTitle('pyqtgraph example: GLViewWidget')
ax = gl.GLAxisItem() ax = gl.GLAxisItem()
ax.setSize(5,5,5) ax.setSize(5,5,5)
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""
Demonstrates GLVolumeItem for displaying volumetric data.
"""
## Add path to library (just for examples; you do not need this) ## Add path to library (just for examples; you do not need this)
import initExample import initExample
...@@ -9,7 +14,7 @@ app = QtGui.QApplication([]) ...@@ -9,7 +14,7 @@ app = QtGui.QApplication([])
w = gl.GLViewWidget() w = gl.GLViewWidget()
w.opts['distance'] = 200 w.opts['distance'] = 200
w.show() w.show()
w.setWindowTitle('pyqtgraph example: GLVolumeItem')
#b = gl.GLBoxItem() #b = gl.GLBoxItem()
#w.addItem(b) #w.addItem(b)
......
# -*- coding: utf-8 -*- # -*- 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 ...@@ -15,7 +16,7 @@ import pyqtgraph.opengl as gl
app = QtGui.QApplication([]) app = QtGui.QApplication([])
w = gl.GLViewWidget() w = gl.GLViewWidget()
w.show() w.show()
w.setWindowTitle('pyqtgraph example: GL Shaders')
w.setCameraPosition(distance=15, azimuth=-90) w.setCameraPosition(distance=15, azimuth=-90)
g = gl.GLGridItem() g = gl.GLGridItem()
......
# -*- coding: utf-8 -*- # -*- 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 initExample ## Add path to library (just for examples; you do not need this)
import pyqtgraph as pg import pyqtgraph as pg
...@@ -10,6 +15,7 @@ import numpy as np ...@@ -10,6 +15,7 @@ import numpy as np
app = QtGui.QApplication([]) app = QtGui.QApplication([])
w = QtGui.QMainWindow() w = QtGui.QMainWindow()
w.show() w.show()
w.setWindowTitle('pyqtgraph example: GradientWidget')
w.resize(400,400) w.resize(400,400)
cw = QtGui.QWidget() cw = QtGui.QWidget()
w.setCentralWidget(cw) w.setCentralWidget(cw)
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
Simple example of GridItem use. Simple example of GraphItem use.
""" """
...@@ -11,6 +11,7 @@ from pyqtgraph.Qt import QtCore, QtGui ...@@ -11,6 +11,7 @@ from pyqtgraph.Qt import QtCore, QtGui
import numpy as np import numpy as np
w = pg.GraphicsWindow() w = pg.GraphicsWindow()
w.setWindowTitle('pyqtgraph example: GraphItem')
v = w.addViewBox() v = w.addViewBox()
v.setAspectLocked() v.setAspectLocked()
......
"""
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) ## Add path to library (just for examples; you do not need this)
import initExample import initExample
...@@ -10,6 +17,7 @@ view = pg.GraphicsView() ...@@ -10,6 +17,7 @@ view = pg.GraphicsView()
l = pg.GraphicsLayout(border=(100,100,100)) l = pg.GraphicsLayout(border=(100,100,100))
view.setCentralItem(l) view.setCentralItem(l)
view.show() view.show()
view.setWindowTitle('pyqtgraph example: GraphicsLayout')
view.resize(800,600)