In this example, a 3D microstructure is generated with grains colored by their seed number, rather than the material.

XML Input File

The basename for this input file is colormap.xml. The file can be run using this command:

microstructpy --demo=colormap.xml

The full text of the script is:

<?xml version="1.0" encoding="UTF-8"?>
        <shape> sphere </shape>
            <dist_type> uniform </dist_type>
            <loc> 1 </loc>
            <scale> 2 </scale>

        <shape> cube </shape>
        <side_length> 15 </side_length>

        <directory> colormap </directory>
        <mesh_min_angle> 15 </mesh_min_angle>
        <color_by> seed number </color_by>
        <colormap> RdYlBu </colormap>


There is a single material with grain sizes ranging from 1 to 3 on a uniform distribution.


The domain of the microstructure is a Cube. The cube’s center is at the origin and its side length is 15.


The output directory is ./colormap, which contains the text files and PNG plots of the microstructure. The minimum dihedral angle for the mesh elements is set to 15 degrees to ensure mesh quality.

The <color_by> option indicates how to color seeds in the output plots. There are three values available for this option: “material”, “seed number”, and “material number”. The “material” value will use colors specified in each <material> field. The “seed number” value will use the seed numbers as values for a colormap. Similarly, “material number” will use the material number in a colormap.

The <colormap> option indicates which colormap should be used in the output plot. The default colormap is “viridis”, which is also the default for matplotlib. A complete listing of available colormaps is available on the matplotlib Choosing Colormaps in Matplotlib webpage.

Output Files

The three plots that this file generates are the seeding, the polygon mesh, and the triangular mesh. These three plots are shown in Fig. 17 - Fig. 19.

Seed geometries.

Fig. 17 Colormap example - seed geometries.

Polygonal mesh.

Fig. 18 Colormap example - polygonal mesh.

Triangular mesh.

Fig. 19 Colormap example - triangular mesh.