visualization
visualization
Functions
| Name | Description |
|---|---|
| annotate_heatmap | Overlays text representation of pixel values within a 2D image |
| annotate_pores | |
| annotate_throats | |
| draw_network | Plot a 2D pore-throat diagram using circular and rectangular patches |
| draw_pores | Plot a 2D diagram of pores using “patches” |
| draw_throats | Plot a 2D diagram of throats using “patches” |
| label_pores | |
| label_throats | |
| plot_edges | Produce a 3D plot of the network topology |
| plot_nodes | Produce a 3D plot showing specified nodecoordinates as markers. |
annotate_heatmap
visualization.annotate_heatmap(
im,
label_by=None,
label_at=None,
ax=None,
font_kwargs={},
**kwargs,
)Overlays text representation of pixel values within a 2D image
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| im | ndarray | A 2D array containing numerical values | required |
| label_by | ndarray | A 2D array the same shape as im with the specific values to write at each location. If not given then the values in im are used. |
None |
| label_at | ndarray | A 2D array the same shape as im with True values at the locations where labels should be applied. If not given then all locations are used. |
None |
| ax | matplotlib axis handle | The handle of the | None |
| font_kwargs | dict | The arguments to send to the text function to control font properties |
{} |
| kwargs | keyword arguments | All other keyword arguments are passed to the pcolormesh function to control the formatting of the heatmap. |
{} |
annotate_pores
visualization.annotate_pores(
network,
pores=None,
font_kws={},
arrow_kws={},
scale=1.0,
ax=None,
)annotate_throats
visualization.annotate_throats(
network,
throats=None,
end_points=None,
scale=1.0,
ax=None,
arrow_kws={},
font_kws={},
)draw_network
visualization.draw_network(
network,
cmap=None,
color_by='diameter',
show_ends=True,
show_centers=True,
end_points=None,
ax=None,
)Plot a 2D pore-throat diagram using circular and rectangular patches
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| network | dict | The OpenPNM network object | required |
| cmap | matplotlib.pyplot cmap object or str | The color map to use. Can be an cmap object or a str of the cmap name. If None (the default) then the pores will be red and throats will be blue, and the prop argument will be ignored. |
None |
| prop | str | The network property to use for coloring the patches. This property must be present on both pores and throats. The default is ‘diameter’. | required |
| show_ends | bool | If True (default), white markers are added at the end points of each throat |
True |
| show_centers | bool | If True (default), black markers are added at the center of each pore |
True |
Returns
| Name | Type | Description |
|---|---|---|
| (fig, ax) | The matplotlib figure and axis objects |
Notes
All the z-coordinates must be equal, but they do not have to be 0.
draw_pores
visualization.draw_pores(
network,
pores=None,
style='circles',
color_by=None,
crange=None,
show_centers=0,
cmap='turbo',
facecolor='tab:red',
scale=1.0,
patch_kwargs={},
ax=None,
)Plot a 2D diagram of pores using “patches”
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| network | dict | The OpenPNM network object | required |
| pores | array_like | A list of which pores to draw. Can be numerical indices or a boolean mask. The default is to plot all pores. | None |
| style | str | The shape of the pores. Options are 'circles' and 'squares', and the default is 'circles'. |
'circles' |
| color_by | ndarray | The network property to use for coloring the patches. If not given then all pores are given the same color, specified by the ‘facecolor’ argument. | None |
| crange | tuple | The (lo, hi) values for the color map. If not provided it will use the min and max of the values in color_by. |
None |
| show_centers | bool | If True (default), black markers are added at the center of each pore |
0 |
| cmap | str or matplotlib colormap object | The default is 'turbo'. This is only used if the color_by argument is specified. |
'turbo' |
| facecolor | str | The color to apply to each pore if color_by is not given. The default is 'tab:red'. |
'tab:red' |
| ax | Matplotlib axis handle | The matplotlib axis on which to add the pore patches. If not given a fresh axis is created. | None |
| patch_kwargs | dict | A dictionary of arguments to pass to the patch drawing function. The default values are: ============== ============================================= arg value ============== ============================================= ‘alpha’ 0.8 ‘edgecolor’ ‘k’ ‘linewidth’ 3 ============== ============================================= |
{} |
Returns
| Name | Type | Description |
|---|---|---|
| ax | Matplotlib axis handle | The matplotlib axis object. This can be passed to draw_throats to add them to the plot |
Notes
All the z-coordinates must be equal, but they do not have to be 0.
draw_throats
visualization.draw_throats(
network,
throats=None,
color_by=None,
crange=None,
cmap='turbo',
end_points=None,
show_ends=0,
ax=None,
facecolor='tab:blue',
patch_kwargs={},
scale=1.0,
)Plot a 2D diagram of throats using “patches”
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| network | dict | The OpenPNM network object | required |
| throats | array_like | A list of which throats to draw. Can be numerical indices or a boolean mask. The default is to plot all throats. | None |
| color_by | ndarray | The network property to use for coloring the patches. If not given then all throats are given the same color, specified by the ‘facecolor’ argument. | None |
| crange | tuple | The (lo, hi) values for the color map. If not provided it will use the min and max of the values in color_by. |
None |
| end_points | str | The dictionary key for the throat endpoint coordinates. If not given the spheres_and_cylinders model is used. |
None |
| show_ends | int | Indicates the size of white markers to add at the endpoints of each throat. If 0 then no markers are drawn. | 0 |
| cmap | str or matplotlib colormap object | The default is 'turbo'. This is only used if the color_by argument is specified. |
'turbo' |
| facecolor | str | The color to apply to each throat if color_by is not given. The default is 'tab:blue'. |
'tab:blue' |
| ax | Matplotlib axis handle | The matplotlib axis on which to add the throat patches. If not given a fresh axis is created. | None |
| patch_kwargs | dict | A dictionary of arguments to pass to the patch drawing function. The default values are: ============== ============================================= arg value ============== ============================================= ‘alpha’ 0.8 ‘edgecolor’ ‘k’ ‘linewidth’ 2 ============== ============================================= |
{} |
Returns
| Name | Type | Description |
|---|---|---|
| ax | Matplotlib axis handle | The matplotlib axis object. This can be passed to draw_pores to add them to the plot |
Notes
All the z-coordinates must be equal, but they do not have to be 0.
label_pores
visualization.label_pores(
network,
pores=None,
label_by=None,
ax=None,
font_kwargs={},
stroke_kwargs={},
)label_throats
visualization.label_throats(
network,
throats=None,
label_by=None,
end_points=None,
ax=None,
font_kwargs={},
)plot_edges
visualization.plot_edges(
network,
edges=None,
ax=None,
size_by=None,
color_by=None,
cmap='jet',
color='b',
alpha=1.0,
linestyle='solid',
linewidth=1,
**kwargs,
)Produce a 3D plot of the network topology
This shows how edges connect for quick visualization without having to export data to veiw in Paraview.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| network | dict | The network dictionary | required |
| edges | array_like(optional) | The list of edges to plot if only a sub-sample is desired. This is useful for inspecting a small region of the network. If no edges are specified then all are shown. | None |
| fig | Matplotlib figure handle and line property arguments (optional) | If a fig is supplied, then the topology will be overlaid on this plot. This makes it possible to combine coordinates and connections, and to color edges differently for instance. |
required |
| size_by | array_like(optional) | An ndarray of edge values (e.g. alg[‘throat.rate’]). These values are used to scale the linewidth, so if the lines are too thin, then increase linewidth. |
None |
| color_by | str or array_like(optional) | An ndarray of edge values (e.g. alg[‘edge.rate’]). | None |
| cmap | str or cmap object (optional) | The matplotlib colormap to use if specfying an edge property for color_by |
'jet' |
| color | (str, optional(optional)) | A matplotlib named color (e.g. ‘r’ for red). | 'b' |
| alpha | float(optional) | The transparency of the lines, with 1 being solid and 0 being invisible | 1.0 |
| linestyle | str(optional) | Can be one of {‘solid’, ‘dashed’, ‘dashdot’, ‘dotted’}. Default is ‘solid’. | 'solid' |
| linewidth | float(optional) | Controls the thickness of drawn lines. Is used to scale the thickness if size_by is given. Default is 1. If a value is provided for size_by then they are used to scale the linewidth. |
1 |
| **kwargs | dict | All other keyword arguments are passed on to the Line3DCollection class of matplotlib, so check their documentation for additional formatting options. |
{} |
Returns
| Name | Type | Description |
|---|---|---|
| lc | LineCollection or Line3DCollection | Matplotlib object containing the lines representing the throats. |
Notes
To create a single plot containing both coordinates and connections, consider creating an empty figure and then passing the ax object as an argument to plot_connections and plot_coordinates. Otherwise, each call to either of these methods creates a new figure.
See Also
plot_coordinates
plot_nodes
visualization.plot_nodes(
network,
nodes=None,
ax=None,
size_by=None,
color_by=None,
cmap='jet',
color='r',
alpha=1.0,
marker='o',
markersize=10,
**kwargs,
)Produce a 3D plot showing specified nodecoordinates as markers.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| network | dict | The network dictionary | required |
| nodes | array_like(optional) | The list of nodes to plot if only a sub-sample is desired. This is useful for inspecting a small region of the network. If no nodes are specified then all are shown. | None |
| ax | Matplotlib axis handle | If ax is supplied, then the coordinates will be overlaid. This enables the plotting of multiple different sets of nodes as well as edge connections from plot_connections. |
None |
| size_by | array_like | An ndarray of node values (e.g. alg[‘node.radius’]). These values are normalized by scaled by markersize. |
None |
| color_by | array_like | An ndarray of node values (e.g. alg[‘node.radius’]). | None |
| cmap | str or cmap object | The matplotlib colormap to use if specfying a node property for color_by |
'jet' |
| color | str | A matplotlib named color (e.g. ‘r’ for red). | 'r' |
| alpha | float | The transparency of the lines, with 1 being solid and 0 being invisible | 1.0 |
| marker | s | The marker to use. The default is a circle. Options are explained here <https://matplotlib.org/3.2.1/api/markers_api.html>_ |
'o' |
| markersize | scalar | Controls size of marker, default is 1.0. This value is used to scale the size_by argument if given. |
10 |
| **kwargs | All other keyword arguments are passed on to the scatter function of matplotlib, so check their documentation for additional formatting options. |
{} |
Returns
| Name | Type | Description |
|---|---|---|
| pc | PathCollection | Matplotlib object containing the markers representing the pores. |
Notes
To create a single plot containing both coordinates and connections, consider creating an empty figure and then passing the ax object as an argument to plot_edges and plot_nodes. Otherwise, each call to either of these methods creates a new figure.
See Also
plot_edges