Visualization¶
In this section, we'll explore the different ways to visualize field data from MICRESS binary files using MicPy.
Built-In Visualization¶
MicPy provides a built-in method to visualize 2D slices of Field
objects. The bin.plot()
method expects a Field
object as input and returns a Matplotlib Figure
and Axes
object.
from micpy import bin
# Read a time series from a binary file
with bin.File("A001_Delta_Gamma.conc1") as file:
series = file.read()
# Plot the last field in the series
field = series.get_field(-1)
fig, ax = bin.plot(field)
The plot()
method also accepts optional arguments axis
and index
. The axis
argument specifies the axis along which the slice is taken, and can be one of the following: x
, y
, or z
. The index
argument specifies the slice index, and has to be an integer.
from micpy import bin
# Read a time series from a binary file
with bin.File("A005_Grain_Growth_Misorientation_3D.korn") as file:
series = file.read()
# Plot the last field in the series along the x-axis
field = series.get_field(-1)
fig, ax = bin.plot(field, axis="x", index=0)
Customizing the Visualization¶
The plot()
method accepts an option argument args
of type PlotArgs
. This dataclass provides a set of optional parameters to customize the visualization. For example, you can set the title, resolution (dpi
), and color map (cmap
).
You can customize the visualization even further by directly modifying the Matplotlib Figure and Axes objects returned by the plot()
method. This allows you to perform any kind of advanced customizations using Matplotlib's extensive functionality.
Combining Multiple Plots¶
You can combine multiple plots into a single figure using Matplotlib's subplots functionality. This allows you to visualize two or more slices of the field data side by side. In the following example, we plot two different fields from the same series in a single figure.
In the example above, each subplot's color map is determined by the minimum and maximum values of the field data. If you want to use identical color maps for both subplots, you can pass the vmin
and vmax
arguments to the PlotArgs
object.
Reference¶
micpy.bin
¶
The micpy.bin
module provides methods to read and write binary files.
PlotArgs
dataclass
¶
Arguments for plotting a field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title | str | Title of the plot. Defaults to | None |
xlabel | str | Label of the x-axis. Defaults to | None |
ylabel | str | Label of the y-axis. Defaults to | None |
figsize | Tuple[float, float] | Figure size. Defaults to | None |
dpi | int | Figure DPI. Defaults to | None |
aspect | str | Aspect ratio. Defaults to | 'equal' |
ax | Axes | Axes of the plot. Defaults to | None |
cax | Axes | Axes of the color bar. Defaults to | None |
vmin | float | Minimum value of the color bar. Defaults to | None |
vmax | float | Maximum value of the color bar. Defaults to | None |
cmap | str | Colormap. Defaults to | 'micpy' |
plot(field, axis='y', index=0, args=None)
¶
Plot a slice of the field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field | Field | Field to plot. | required |
axis | str | Axis to plot. Possible values are | 'y' |
index | int | Index of the slice. Defaults to | 0 |
args | PlotArgs | Arguments for plotting. Defaults to | None |
Returns:
Type | Description |
---|---|
Tuple[Figure, Axes] | Matplotlib figure and axes of the plot. |