Hello everyone,
I am trying to implement a scalar bar for improving data reading. The particularity is that I want to have a specific colormap for the data and the scalar bar. I am wondering whether or not it is possible to use Matplotlib colormaps (such as “viridis”, “plasma”, …) for creating a scalar bar and how to do it?
My code (in python) is as follows:
#########################
import vtk #version 8.1.2
from matplotlib import cm
def set_colors(data):
cmap = cm.get_cmap(‘viridis’)
colors = cmap(data)[:, :3]
return colors
def main():
coordinates = [[-29, 19, -19], [-34, 19, -19], [-39, 19, -19], [-44, 19, -19],[-49, 19, -19]]
data = [0.1, 0.2, 0.3, 0.4, 0.5]
renderer = vtk.vtkRenderer()
renWindow = vtk.vtkRenderWindow()
renWindow.AddRenderer(renderer)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWindow)
rgb_colors = set_colors(data)
for i in range(0, len(coordinates)):
sphere = vtk.vtkSphereSource()
sphere.SetCenter(coordinates[i][0],coordinates[i][1],coordinates[i][2])
sphere.SetRadius(2)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(sphere.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetColor(rgb_colors[i][0], rgb_colors[i][1], rgb_colors[i][2])
renderer.AddActor(actor)
iren.Initialize()
iren.Start()
if name == ‘main’:
main()
#########################
Thank for your help!