2012-12-26 20:22:44 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-02-25 04:09:03 +00:00
|
|
|
"""
|
|
|
|
Demonstrate use of GLLinePlotItem to draw cross-sections of a surface.
|
|
|
|
|
|
|
|
"""
|
2012-12-26 20:22:44 +00:00
|
|
|
## Add path to library (just for examples; you do not need this)
|
2012-12-26 22:51:52 +00:00
|
|
|
import initExample
|
2012-12-26 20:22:44 +00:00
|
|
|
|
|
|
|
from pyqtgraph.Qt import QtCore, QtGui
|
|
|
|
import pyqtgraph.opengl as gl
|
|
|
|
import pyqtgraph as pg
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
app = QtGui.QApplication([])
|
|
|
|
w = gl.GLViewWidget()
|
|
|
|
w.opts['distance'] = 40
|
|
|
|
w.show()
|
2013-02-25 04:09:03 +00:00
|
|
|
w.setWindowTitle('pyqtgraph example: GLLinePlotItem')
|
2012-12-26 20:22:44 +00:00
|
|
|
|
|
|
|
gx = gl.GLGridItem()
|
|
|
|
gx.rotate(90, 0, 1, 0)
|
|
|
|
gx.translate(-10, 0, 0)
|
|
|
|
w.addItem(gx)
|
|
|
|
gy = gl.GLGridItem()
|
|
|
|
gy.rotate(90, 1, 0, 0)
|
|
|
|
gy.translate(0, -10, 0)
|
|
|
|
w.addItem(gy)
|
|
|
|
gz = gl.GLGridItem()
|
|
|
|
gz.translate(0, 0, -10)
|
|
|
|
w.addItem(gz)
|
|
|
|
|
|
|
|
def fn(x, y):
|
|
|
|
return np.cos((x**2 + y**2)**0.5)
|
|
|
|
|
|
|
|
n = 51
|
|
|
|
y = np.linspace(-10,10,n)
|
|
|
|
x = np.linspace(-10,10,100)
|
|
|
|
for i in range(n):
|
|
|
|
yi = np.array([y[i]]*100)
|
|
|
|
d = (x**2 + yi**2)**0.5
|
|
|
|
z = 10 * np.cos(d) / (d+1)
|
|
|
|
pts = np.vstack([x,yi,z]).transpose()
|
2013-03-31 02:39:11 +00:00
|
|
|
plt = gl.GLLinePlotItem(pos=pts, color=pg.glColor((i,n*1.3)), width=(i+1)/10., antialias=True)
|
2012-12-26 20:22:44 +00:00
|
|
|
w.addItem(plt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 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_()
|