Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
fb06733
Move 2D test data to top level of Axes unittest
eldond May 25, 2018
972870b
Start adding contour functions
eldond May 25, 2018
479f1f7
Merge branch 'master' into contour
eldond May 26, 2018
f983276
Merge branch 'master' into contour
eldond May 26, 2018
1a42726
Merge branch 'dev' into contour
eldond Jun 2, 2018
4e5b9cb
Add some contour junk
eldond Jun 28, 2018
8b402a5
Merge branch 'dev' into contour
eldond Jun 29, 2018
6d57263
Merge branch 'dev' into contour
eldond Jun 29, 2018
f4b7445
Contour setup stuff
eldond Jun 29, 2018
18b60bb
Very basic semi-working contour
eldond Jun 29, 2018
34bd3e4
Add test of contour errors
eldond Jun 29, 2018
42d8b74
Move legend to new file
eldond Jun 29, 2018
df79f29
Fix names in test_legend.py
eldond Jun 29, 2018
65a5591
Translate and scale contours
eldond Jun 29, 2018
0c72e2a
Color map for contour()
eldond Jun 30, 2018
9fbc916
Handling of linestyles and linewidths in contour
eldond Jun 30, 2018
d2b4584
Cleanup
eldond Jun 30, 2018
fff6d2e
Test manual colors to contour (instead of cmap)
eldond Jun 30, 2018
7907186
WIP: working on filled contours
eldond Jun 30, 2018
04ac2a2
Fix up utilities to support filled contours
eldond Jul 2, 2018
48ac8bc
Merge branch 'dev' into contourf
eldond Jul 4, 2018
c3d647f
Method for closing and scaling contour paths
eldond Aug 4, 2018
bc85bde
Fix contourf test
eldond Aug 4, 2018
3ff8b06
Switch orientation of z input to contour for consistency w/ matplotlib
eldond Aug 4, 2018
cc3fd15
Rename internal methods in contour
eldond Aug 4, 2018
18036d9
Fill center of first contour
eldond Aug 4, 2018
abc462b
Change default level count and padding to try to match mpl better
eldond Aug 4, 2018
70a79bd
Empty line defaults to boundary
eldond Aug 4, 2018
f46506c
New idea for joining segments
eldond Aug 4, 2018
499ccc1
Fix contourf plan
eldond Aug 5, 2018
908ecc1
Improve contourf
eldond Aug 5, 2018
1032576
Expand testing of contourf
eldond Sep 18, 2018
2db7e97
Adjust contourf test
eldond Sep 18, 2018
4eda739
Flip sign in one of the test `z`s to make contour test more interesting
eldond Sep 18, 2018
025fa08
Attempt to fix filled contours
eldond Sep 18, 2018
ffe3879
Stuff I had uncommitted locally; probably just dev trash to remove
eldond May 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions contour_example_gl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# -*- coding: utf-8 -*-
"""
This example demonstrates the use of GLSurfacePlotItem.
"""


## Add path to library (just for examples; you do not need this)
#import initExample

from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph as pg
import pyqtgraph.opengl as gl
import numpy as np

## Create a GL View widget to display data
app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.show()
w.setWindowTitle('pyqtgraph example: GLSurfacePlot')
w.setCameraPosition(distance=50)

## Add a grid to the view
g = gl.GLGridItem()
g.scale(2,2,1)
g.setDepthValue(10) # draw grid after surfaces since they may be translucent
w.addItem(g)


## Simple surface plot example
## x, y values are not specified, so assumed to be 0:50
z = pg.gaussianFilter(np.random.normal(size=(50,50)), (1,1))
p1 = gl.GLSurfacePlotItem(z=z, shader='shaded', color=(0.5, 0.5, 1, 1))
p1.scale(16./49., 16./49., 1.0)
p1.translate(-18, 2, 0)
w.addItem(p1)


## Saddle example with x and y specified
x = np.linspace(-8, 8, 50)
y = np.linspace(-8, 8, 50)
z = 0.1 * ((x.reshape(50,1) ** 2) - (y.reshape(1,50) ** 2))
p2 = gl.GLSurfacePlotItem(x=x, y=y, z=z, shader='normalColor')
p2.translate(-10,-10,0)
w.addItem(p2)


## Manually specified colors
z = pg.gaussianFilter(np.random.normal(size=(50,50)), (1,1))
x = np.linspace(-12, 12, 50)
y = np.linspace(-12, 12, 50)
colors = np.ones((50,50,4), dtype=float)
colors[...,0] = np.clip(np.cos(((x.reshape(50,1) ** 2) + (y.reshape(1,50) ** 2)) ** 0.5), 0, 1)
colors[...,1] = colors[...,0]

p3 = gl.GLSurfacePlotItem(z=z, colors=colors.reshape(50*50,4), shader='shaded', smooth=False)
p3.scale(16./49., 16./49., 1.0)
p3.translate(2, -18, 0)
w.addItem(p3)




## Animated example
## compute surface vertex data
cols = 90
rows = 100
x = np.linspace(-8, 8, cols+1).reshape(cols+1,1)
y = np.linspace(-8, 8, rows+1).reshape(1,rows+1)
d = (x**2 + y**2) * 0.1
d2 = d ** 0.5 + 0.1

## precompute height values for all frames
phi = np.arange(0, np.pi*2, np.pi/20.)
z = np.sin(d[np.newaxis,...] + phi.reshape(phi.shape[0], 1, 1)) / d2[np.newaxis,...]


## create a surface plot, tell it to use the 'heightColor' shader
## since this does not require normal vectors to render (thus we
## can set computeNormals=False to save time when the mesh updates)
p4 = gl.GLSurfacePlotItem(x=x[:,0], y = y[0,:], shader='heightColor', computeNormals=False, smooth=False)
p4.shader()['colorMap'] = np.array([0.2, 2, 0.5, 0.2, 1, 1, 0.2, 0, 2])
p4.translate(10, 10, 0)
w.addItem(p4)

index = 0
def update():
global p4, z, index
index -= 1
p4.setData(z=z[index%z.shape[0]])

timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(30)

## Start Qt event loop unless running in interactive mode.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

42 changes: 42 additions & 0 deletions contour_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
import sys

# Setup
app = QtGui.QApplication([])
pg.setConfigOption('background', 'w')
pg.setConfigOption('foreground', 'k')

win = pg.PlotWidget()
layout = pg.GraphicsLayout()
win.setCentralItem(layout)
ax = pg.PlotItem()
layout.addItem(ax)

# Generate data
x = np.linspace(10, 16.28, 30)
y = x[:]
xx, yy = np.meshgrid(x, y)
z = np.sin(xx) + np.cos(yy)

# Add data
ax.setXRange(x.min(), x.max())
ax.setYRange(y.min(), y.max())

c = pg.IsocurveItem(data=z, level=0.5, pen='r', axisOrder='row-major')
img = pg.ImageItem(z, axisOrder='row-major')
img.translate(x.min(), y.min())
img.scale((x.max() - x.min()) / img.width(), (y.max() - y.min()) / img.height())
ax.addItem(img)

# c.setParentItem(img)
# https://stackoverflow.com/a/51109935/6605826
c.translate(x.min(), y.min())
c.scale((x.max() - x.min()) / np.shape(z)[0], (y.max() - y.min()) / np.shape(z)[1])

ax.addItem(c)

# Finish up
win.show()
sys.exit(app.exec_())
32 changes: 32 additions & 0 deletions contour_sample2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
import sys

# Setup
app = QtGui.QApplication([])
pg.setConfigOption('background', 'w')
pg.setConfigOption('foreground', 'k')

win = pg.PlotWidget()
layout = pg.GraphicsLayout()
win.setCentralItem(layout)
ax = pg.PlotItem()
layout.addItem(ax)

# Generate data
x = np.linspace(0, 6.28, 30)
y = x[:]
xx, yy = np.meshgrid(x, y)
z = np.sin(xx) + np.cos(yy)

# Add data
#ax.setXRange(x.min(), x.max())
#ax.setYRange(y.min(), y.max())
c = pg.IsocurveItem(data=z, level=0.5, pen='r', axisOrder='row-major')
# c.setParentItem(ax) # This doesn't work, of course
ax.addItem(c)

# Finish up
win.show()
sys.exit(app.exec_())
Loading