Plot Data per Grain with Scatter

  • Contributor: Martin Diehl (

  • DAMASK version: 3.0.0-alpha5

  • Prerequisites (Python): seaborn

  • Prerequisites (data): DADF5 results file with 1. Piola-Kirchhoff stress (‘P’) and deformation gradient (‘F’)

%pylab inline
%matplotlib inline
Populating the interactive namespace from numpy and matplotlib
import damask
import numpy as np
import pandas as pd
import seaborn as sns
# adjust to your situation
result_file = 'plot_per_grain_scatter/20grains16x16x16_tensionX.hdf5'

grains = [1,4,19] # corresponds to the material ID in the vti file/material.yaml
result = damask.Result(result_file)
grid_file = '20grains16x16x16.vti'
grid   = damask.Grid.load(grid_file)
Exported geometry definition (grid solver) to '20grains16x16x16.vti'.
Exported main configuration to 'material.yaml'.
Exported numerics configuration to 'numerics.yaml'.
Exported load case definition (grid solver) to 'tensionX.yaml'.
# loop over all increments and store P(1,1) per grain and avg(F(1,1))
data = {g:pd.DataFrame() for g in grains}
for inc in result.get(['F','P']).values():
    P = inc['P']
    F = inc['F']
    for g in grains:
        points = grid.material.flatten(order='F')==g
        P_11 = P[points,0,0].flatten()
        F_11 = np.broadcast_to(np.average(F[:,0,0]),P_11.shape)
        x = pd.DataFrame({'F_11':F_11,'P_11':P_11})
        data[g] = data[g].append(x,ignore_index=True)
 ██████████████████████████████████████████████████ 100% ETA 0:00:00
for g in grains:
   plot = sns.lineplot(y='P_11',x='F_11',data=data[g])

fig = plot.get_figure()