# no color when using python vtk rendering vtkfile with vtkpolydata，but it\`s ok with paraview

**URL:** https://discourse.vtk.org/t/no-color-when-using-python-vtk-rendering-vtkfile-with-vtkpolydata-but-it-s-ok-with-paraview/13589
**Category:** Support
**Tags:** python, code, file-formats
**Created:** [March 20, 2024, 12:02pm UTC](https://discourse.vtk.org/t/no-color-when-using-python-vtk-rendering-vtkfile-with-vtkpolydata-but-it-s-ok-with-paraview/13589 "2024-03-20T12:02:39Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![alphacheng](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alphacheng/32/7913_2.png) [@alphacheng](https://discourse.vtk.org/u/alphacheng)
#### Post date: [March 20, 2024, 12:02pm UTC](https://discourse.vtk.org/t/no-color-when-using-python-vtk-rendering-vtkfile-with-vtkpolydata-but-it-s-ok-with-paraview/13589/1 "2024-03-20T12:02:39Z")

</div>

```python
import vtk

filename = "test.vtk"

#reader
reader = vtk.vtkPolyDataReader()
reader.SetFileName(filename)
reader.Update()
grid = reader.GetOutput()
field = "mag(U)"
data_type = "cell"
magU = grid.GetPointData().GetArray("VelocityMagnitude")
array_name = "VelocityMagnitude"
array = magU

# lookup table
lut = vtk.vtkLookupTable()
lut.SetRange(array.GetRange())
lut.SetHueRange(0.667, 0)
lut.Build()

# mapper
mapper = vtk.vtkDataSetMapper()
mapper.SetInputConnection(reader.GetOutputPort())
mapper.SetScalarModeToUsePointData()
mapper.SelectColorArray(array_name)
mapper.SetColorModeToDirectScalars()
mapper.SetScalarRange(array.GetRange())
mapper.ScalarVisibilityOn()
mapper.SetLookupTable(lut)

# actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.SetOrientation(0,0,0)
# prop = actor.GetProperty()
# prop.SetAmbient(0.5)
# prop.EdgeVisibilityOn()
# prop.SetEdgeColor(0, 0, 0)
# prop.SetLineWidth(2)
# prop.SetRepresentationToSurface()
# renderer

ren = vtk.vtkRenderer()

ren.AddActor(actor)

ren.SetBackground(1, 1, 1)

ren_win = vtk.vtkRenderWindow()

ren_win.AddRenderer(ren)

ren_win.SetSize(640, 480)

# interactor

inter = vtk.vtkRenderWindowInteractor()

inter.SetRenderWindow(ren_win)

#inter.SetInteractorStyle(MouseInteractorStyle())

# scalar bar

scalar_bar = vtk.vtkScalarBarActor()

scalar_bar.SetOrientationToVertical()

scalar_bar.SetLookupTable(lut)

prop = vtk.vtkTextProperty()

prop.SetColor(0, 0, 0)

prop.SetFontSize(20)

scalar_bar.UnconstrainedFontSizeOn()

scalar_bar.SetTitleTextProperty(prop)

scalar_bar.SetLabelTextProperty(prop)

scalar_bar.SetTitle(array_name)

ren.AddActor(scalar_bar)

# text

text = vtk.vtkTextActor()

text.SetInput(array_name)

text.GetTextProperty().SetColor(0, 0, 0)

text.GetTextProperty().SetFontSize(24)

text.SetPosition(300, 30)

ren.AddActor(text)

ren_win.Render()

inter.Initialize()

inter.Start()

```
