Hello everyone,
I’m trying to use the OVITO python API to visualise my simulations. In the process I’m trying to color particles by type and print a legend with their names. However, the legend is printed in the default colors, and I can’t change the colors. I’ve tried assigning the pipeline (it is the only pipeline in the script) and using the ColorCodingModifier and color_mapping_source. Both of them only give me gradients to work with. I’d appreciate any insight.
pipeline1 = ov.io.import_file(dumpfilename)
pipeline1.add_to_scene()
pipeline1.modifiers.append(ov.modifiers.SelectTypeModifier(types={1}))
pipeline1.modifiers.append(ov.modifiers.AssignColorModifier(color=(0.490, 0.737, 0)))
pipeline1.modifiers.append(ov.modifiers.SelectTypeModifier(types={2}))
pipeline1.modifiers.append(ov.modifiers.AssignColorModifier(color=(1, 0, 0.5)))
vp = ov.vis.Viewport()
legend = ov.vis.ColorLegendOverlay(
title = 'Particle type',
alignment = QtCore.Qt.AlignmentFlag.AlignRight | QtCore.Qt.AlignmentFlag.AlignTop,
orientation = QtCore.Qt.Orientation.Horizontal,
offset_y = -0.04,
font_size = 0.08,
pipeline = pipeline1,
property = 'particles/Particle Type'
)
vp.overlays.append(legend)