It is now quite simple to create a 2D stream using python and matplotlib because streamplot was recently included in matplotlib by Tom Flannagan and Tony U.
Although you can create certain types of 3D plots with matplotlib, 3D streams are not currently supported. However, the python plotting mayavi program (which provides the vtk-based python interface) is able to create 3D streams using the flow () function .
I created a simple python module for streaming data in 2D and 3D without a Z-slope (all dZ = 0) in a 3D data set to demonstrate the graphing problem that I faced with Mayavi versus matplotlib by effectively matching data in the xy plane . The commented code and the resulting graphs are shown below:
import numpy, matplotlib, mayavi, matplotlib.pyplot, mayavi.mlab
x = numpy.ones((10,10))
y = numpy.ones((10,10))
Y,X = numpy.mgrid[-10:10:10j,-10:10:10j]
xx = numpy.ones((10,10,10))
yy = numpy.ones((10,10,10))
zz = numpy.zeros((10,10,10))
ZZ,YY,XX = numpy.mgrid[-10:10:10j,-10:10:10j,-10:10:10j]
fig = matplotlib.pyplot.figure()
ax = fig.add_subplot(111,aspect='equal')
speed = numpy.sqrt(x*x + y*y)
ax.streamplot(X, Y, x, y, color=x, linewidth=2, cmap=matplotlib.pyplot.cm.autumn,arrowsize=3)
fig.savefig('test_streamplot_2D.png',dpi=300)
fig = mayavi.mlab.figure(bgcolor=(1.0,1.0,1.0),size=(800,800),fgcolor=(0, 0, 0))
st = mayavi.mlab.flow(XX,YY,ZZ,xx,yy,zz,line_width=4,seedtype='sphere',integration_direction='forward')
mayavi.mlab.axes(extent = [-10.0,10.0,-10.0,10.0,-1.0,1.0])
fig.scene.z_plus_view()
mayavi.mlab.savefig('test_streamplot_3D_attempt_1.png')
fig = mayavi.mlab.figure(bgcolor=(1.0,1.0,1.0),size=(800,800),fgcolor=(0, 0, 0))
st = mayavi.mlab.flow(XX,YY,ZZ,xx,yy,zz,line_width=4,seedtype='line',integration_direction='forward')
st.seed.widget.point1 = [0,-10,0]
st.seed.widget.point2 = [0,10,0]
st.seed.widget.resolution = 25
mayavi.mlab.axes(extent = [-10.0,10.0,-10.0,10.0,-1.0,1.0])
fig.scene.z_plus_view()
mayavi.mlab.savefig('test_streamplot_3D_attempt_2.png')
fig = mayavi.mlab.figure(bgcolor=(1.0,1.0,1.0),size=(800,800),fgcolor=(0, 0, 0))
st = mayavi.mlab.flow(XX,YY,ZZ,xx,yy,zz,line_width=4,seedtype='line',integration_direction='forward')
st.seed.widget.point1 = [-10,10,0]
st.seed.widget.point2 = [10,-10,0]
st.seed.widget.resolution = 25
mayavi.mlab.axes(extent = [-10.0,10.0,-10.0,10.0,-1.0,1.0])
fig.scene.z_plus_view()
mayavi.mlab.savefig('test_streamplot_3D_attempt_3.png')
2D matplotlib ( , 1 dx dy, ):
3D mayavi ( 1; ) , , , , , , 2D matplotlib):
3D mayavi ( 2; ) , , , - , )
, β3 () , # 2, /. , , , ? , 3D- (), .
, , :
- matplotlib streamplot Tom Flannaghan
- , Mayavi Streamline (, , ( )), , , .
- , , 2D- .
- 3D, :
- flow() , Mayavi ( , ).