grains.analysis.plot_grain_characteristic¶
-
grains.analysis.
plot_grain_characteristic
(characteristic, centers, interpolation='linear', grid_size=(100, 100), **kwargs)[source]¶ Plots the distribution of a given grain characteristic.
One way to gain insight into a grain assembly is to plot the distribution of a certain grain property in the domain the grains occupy. In this function, for each grain, and arbitrary (scalar) quantity is associated to the center of the grain. In case of n grains, n data points span the interpolant and the given characteristic is interpolated on a grid of the AABB of the grain centers.
- Parameters
characteristic (ndarray) – Characteristic property, the distribution of which is sought. A 1D numpy array.
centers (ndarray) – 2D numpy array with 2 columns, each row corresponding to a grain, and the two columns giving the Cartesian coordinates of the grain center.
interpolation ({‘nearest’, ‘linear’, ‘cubic’}, optional) – Type of the interpolation for creating the distribution. The default is ‘linear’.
grid_size (tuple of int, optional) – 2-tuple, the size of the grid on which the data is interpolated. The default is (100, 100).
- Other Parameters
center_marker (str, optional) – Marker indicating the center of the grains. The default is ‘P’. For a list of supported markers, see the documentation. If you do not want the centers to be shown, choose ‘none’.
show_axis (bool, optional) – If True, the axes are displayed. The default is False.
- Returns
None
See also
Notes
This function knows nothing about how the center of a grain is determined and what characteristic features a grain has. It only performs interpolation and visualization, hence decoupling the plotting from the actual representation of grains and their characteristics. For instance, a grain can be represented as a spline surface, as a polygon, as an assembly of primitives (often triangles), as pixels, just to mention some typical scenarios. Calculating the center of a grain depends on the grain representation at hand. Similarly, one can imagine various grain characteristics, such as area, diameter, Young modulus.
Examples
Assume that the grain centers are sampled from a uniformly random distribution on the unit square.
>>> n_data = 100 >>> points = np.random.random((n_data, 2))
The quantity we want to plot has a parabolic distribution with respect to the position of the grain centers.
>>> func = lambda x, y: 1 - (x-0.5)**2 - (y-0.5)**2 >>> plot_grain_characteristic(func(points[:, 0], points[:, 1]), points, center_marker='*') >>> plt.show()