In [1]:
import numpy as np
import matplotlib.pyplot as plt
import vtk
from tvtk.api import tvtk


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-d20bc813ed31> in <module>()
      1 import numpy as np
      2 import matplotlib.pyplot as plt
----> 3 import vtk
      4 from tvtk.api import tvtk

ImportError: No module named vtk

In [2]:
# equidistant

x = np.arange(10)
y = np.arange(10)
X, Y = np.meshgrid(x, y)

U = np.random.random((10, 10))
V = np.random.random((10, 10))
u = U.ravel()
v = V.ravel()
# slurp em in
U[5:,:] *= -1
V[:,:5] *= -1

In [15]:
plt.streamplot(X, Y, U, V, linewidth=np.sqrt(U**2 + V**2)*2)


Out[15]:
<matplotlib.streamplot.StreamplotSet at 0x6010e50>

In [28]:
tracer = tvtk.TemporalStreamTracer().print_traits
vectors = (np.c_[u, v, np.zeros(u.shape)])
grid = tvtk.PolyData()
grid.points = np.c_[X.ravel(), Y.ravel(), np.zeros(X.ravel().shape)]
grid.point_data.vectors = vectors
print grid.print_traits()


_in_set:                   0
_vtk_obj:                  (vtkPolyData)0x64ac9f0
actual_memory_size:        6
bounds:                    (0.0, 9.0, 0.0, 9.0, 0.0, 0.0)
cell_data:                 <tvtk.tvtk_classes.cell_d...ata object at 0x5db8230>
center:                    (4.5, 4.5, 0.0)
class_name:                'vtkPolyData'
data_object_type:          0
data_released:             0
debug:                     0
debug_:                    0
estimated_memory_size:     0
extent_translator:         <tvtk.tvtk_classes.extent...tor object at 0x5db8230>
extent_type:               0
field_data:                <tvtk.tvtk_classes.field_...ata object at 0x5db8230>
ghost_level:               0
global_release_data_flag:  0
global_release_data_flag_: 0
global_warning_display:    1
global_warning_display_:   1
information:               <tvtk.tvtk_classes.inform...ion object at 0x5db8230>
length:                    12.727922061357855
lines:                     <tvtk.tvtk_classes.cell_a...ray object at 0x5db8230>
m_time:                    1332
max_cell_size:             0
maximum_number_of_pieces:  -1
number_of_cells:           0L
number_of_lines:           0L
number_of_pieces:          1
number_of_points:          100L
number_of_polys:           0L
number_of_strips:          0L
number_of_verts:           0L
piece:                     -1
pipeline_information:      <tvtk.tvtk_classes.inform...ion object at 0x5db8230>
pipeline_m_time:           0
point_data:                <tvtk.tvtk_classes.point_...ata object at 0x5db8230>
points:                    [(0.0, 0.0, 0.0), ..., (9...9.0, 0.0)], length = 100
polys:                     <tvtk.tvtk_classes.cell_a...ray object at 0x5dc0d70>
producer_port:             <tvtk.tvtk_classes.algori...put object at 0x5dc0d70>
reference_count:           3
release_data_flag:         0
release_data_flag_:        0
request_exact_extent:      0
request_exact_extent_:     0
scalar_range:              (0.0, 1.0)
source:                    None
strips:                    <tvtk.tvtk_classes.cell_a...ray object at 0x5db8230>
update_extent:             array([ 0, -1,  0, -1,  0, -1])
update_ghost_level:        0
update_number_of_pieces:   1
update_piece:              0
update_time:               0
verts:                     <tvtk.tvtk_classes.cell_a...ray object at 0x5dc0d70>
whole_bounding_box:        array([ 0., -1.,  0., -1.,  0., -1.])
whole_extent:              array([ 0, -1,  0, -1,  0, -1])
None

In [31]:
contour = tvtk.ContourFilter()
contour.input = grid

In [39]:
contour.number_of_contours = 2
contour.output.print_traits()


_in_set:                   0
_vtk_obj:                  (vtkPolyData)0x6585470
actual_memory_size:        0
bounds:                    (1.0, -1.0, 1.0, -1.0, 1.0, -1.0)
cell_data:                 <tvtk.tvtk_classes.cell_d...ata object at 0x6563e30>
center:                    (0.0, 0.0, 0.0)
class_name:                'vtkPolyData'
data_object_type:          0
data_released:             0
debug:                     0
debug_:                    0
estimated_memory_size:     0
extent_translator:         <tvtk.tvtk_classes.extent...tor object at 0x6563e30>
extent_type:               0
field_data:                <tvtk.tvtk_classes.field_...ata object at 0x6563e30>
ghost_level:               0
global_release_data_flag:  0
global_release_data_flag_: 0
global_warning_display:    1
global_warning_display_:   1
information:               <tvtk.tvtk_classes.inform...ion object at 0x6563e30>
length:                    0.0
lines:                     <tvtk.tvtk_classes.cell_a...ray object at 0x6563e30>
m_time:                    1723
max_cell_size:             0
maximum_number_of_pieces:  -1
number_of_cells:           0L
number_of_lines:           0L
number_of_pieces:          1
number_of_points:          0L
number_of_polys:           0L
number_of_strips:          0L
number_of_verts:           0L
piece:                     -1
pipeline_information:      <tvtk.tvtk_classes.inform...ion object at 0x6563e30>
pipeline_m_time:           1696
point_data:                <tvtk.tvtk_classes.point_...ata object at 0x6563e30>
points:                    None
polys:                     <tvtk.tvtk_classes.cell_a...ray object at 0x6563e30>
producer_port:             <tvtk.tvtk_classes.algori...put object at 0x6563110>
reference_count:           2
release_data_flag:         0
release_data_flag_:        0
request_exact_extent:      0
request_exact_extent_:     0
scalar_range:              (0.0, 1.0)
source:                    None
strips:                    <tvtk.tvtk_classes.cell_a...ray object at 0x6563e30>
update_extent:             array([ 0, -1,  0, -1,  0, -1])
update_ghost_level:        0
update_number_of_pieces:   1
update_piece:              0
update_time:               0
verts:                     <tvtk.tvtk_classes.cell_a...ray object at 0x6563110>
whole_bounding_box:        array([ 0., -1.,  0., -1.,  0., -1.])
whole_extent:              array([ 0, -1,  0, -1,  0, -1])

In [ ]: