# I'm not able to change the default colormap in VTK (python)

**URL:** https://discourse.vtk.org/t/im-not-able-to-change-the-default-colormap-in-vtk-python/7546
**Category:** Support
**Created:** [January 2, 2022, 9:39pm UTC](https://discourse.vtk.org/t/im-not-able-to-change-the-default-colormap-in-vtk-python/7546 "2022-01-02T21:39:16Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Altertango](https://discourse.vtk.org/user_avatar/discourse.vtk.org/altertango/32/4491_2.png) [@Altertango](https://discourse.vtk.org/u/Altertango)
#### Post date: [January 2, 2022, 9:39pm UTC](https://discourse.vtk.org/t/im-not-able-to-change-the-default-colormap-in-vtk-python/7546/1 "2022-01-02T21:39:16Z")

</div>

Hello and happy new year to everyone,

I’m trying to import some triangulated surfaces DEMs (digital elevation models) from a csv file to vtk. I have no problem importing the file and creating the triangles in VTK, I also wanted to add a colormap for elevation. I managed to add the scalar values and it automatically creates a black and white colormap if i set the scalars with a range from 0 to 255. But somehow I cannot manage to change any properties of this automatic LookUpTable that is being created.

Here is the code to create the triangulates surface (with zcolor set to True):

```auto
def tri2poly(tri,zcolor=False):
        #setup points and vertices
    Points = vtk.vtkPoints()
    Triangles = vtk.vtkCellArray()
    
    #puntos de los vertices del primer triangulo
    if zcolor: 
        Zs=[]
        min=float('inf')
        max=float('-inf')
    for vert in tri:
        for i in range(0,3):
            Points.InsertNextPoint(vert[i])
            if zcolor:
                z=vert[i][2]
                Zs.append(z)
                if z<min: min=z
                if z>max: max=z
    if zcolor: 
        Colors = vtk.vtkUnsignedCharArray()
        Colors.SetNumberOfComponents(1)
        Colors.SetName("Colors")
        Zs_norm=[255*(z-min)/(max-min) for z in Zs]
        
    for i in range(0,len(tri)):
        Triangle = vtk.vtkTriangle()
        Triangle.GetPointIds().SetId(0, i*3)
        Triangle.GetPointIds().SetId(1, i*3+1)
        Triangle.GetPointIds().SetId(2, i*3+2)
        Triangles.InsertNextCell(Triangle)
        if zcolor: 
            Colors.InsertNextTuple1(Zs_norm[i*3])
            Colors.InsertNextTuple1(Zs_norm[i*3+1])
            Colors.InsertNextTuple1(Zs_norm[i*3+2])

    #create polydata and add triangles
    polydata = vtk.vtkPolyData()
    polydata.SetPoints(Points)
    polydata.SetPolys(Triangles)
    if zcolor: 
        #ingresar los datos de los atributos
        polydata.GetPointData().AddArray(Colors)
        #definir cual atributo define el color por default
        polydata.GetPointData().SetActiveScalars("Colors")
    return polydata

```

And here is the code to plot the data. For some reason, it simple wont respond to any changes in the lut settings. I can skip the lut altogether and it will always display the same black and white colorbar. Set scalarRange doesnt seem to change anything either, it always chooses to use 0 to 255.

```auto
def plotPolydata(polydata):
    
    colors = vtk.vtkNamedColors()
    
    #This LUT does nothing??
    lut=vtk.vtkLookupTable()
    # lut.SetValueRange(0,255)
    # lut.SetSaturationRange(0,1)
    lut.SetHueRange(0.667, 1)
    lut.Build()

    
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputData(polydata)
    #mapper.ScalarVisibilityOff()
    mapper.SetLookupTable(lut)
    #mapper.SetScalarRange(0,100)
    #mapper.SetScalarRange(polydata.GetScalarRange())

    
    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    #actor.GetProperty().SetColor(colors.GetColor3d('Tan'))

    # Create a rendering window and renderer
    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    renWin.SetWindowName('Preview')
    renWin.SetSize(640,480)

    # Create a renderwindowinteractor
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    # Assign actor to the renderer
    ren.AddActor(actor)

    # Enable user interface interactor
    iren.Initialize()
    renWin.Render()

    ren.SetBackground(colors.GetColor3d('AliceBlue'))
    renWin.Render()
    iren.Start()

```

If someone can guide me to solve this problem I would be very grateful.

Cheers,  
Ignacio Villalón
