colorize
- PolyGraph.colorize(scalars, items, interpolate_scalars=False)
Colorize polygonal data.
Colorize by assinging vertex colors or face colors. Vertex colors are interpolated across faces. Colors can be specified directly as RGB intensity triples or via a color map that maps scalar values to colors (see
lookuptable()
for details on the mapping).- Parameters:
scalars (array_like) – Scalar values.
items (str) – Either ‘verts’ or ‘cells’.
Note
Use the
colorbar()
function to display a visual representation of the lookup table used for color mapping.Examples
Apply colors to the vertices of the unit cube \([0, 1]^3\). Since vertex coordinates range between 0 and 1 we use them directly as RGB color specification.
1import m3sh.vis as vis 2 3box = vis.box([0., 0., 0.], [1., 1., 1.]) 4box.edges() 5box.colorize(box.points, 'verts') 6 7vis.show()
Color the cube by \(z\)-coordinate value. Not the difference when interpolating scalars before mapping them to colors.
1import m3sh.vis as vis 2 3box = vis.box([0., 0., 0.], [1., 1., 1.]) 4box.edges() 5box.colorize(box.points[:, 2], 'verts', interpolate_scalars=True) 6 7vis.colorbar(box) 8vis.show()
To map colors to faces we have to specify a scalar for each of the six faces of the cube. Note that the interpolate_scalars argument has no effect when mapping colors to faces.
1import m3sh.vis as vis 2 3box = vis.box([0., 0., 0.], [1., 1., 1.]) 4box.edges() 5box.colorize([.0, .2, .4, .6, .8, 1.], 'cells') 6 7vis.colorbar(box) 8vis.show()