porepy.viz.plot_grid module

Module for PorePy’s plotting functionality for (mixed-dimensional grids) built on matplotlib.

The functionality provided covers plotting of grids in 0 to 3 dimensions. Data may be represented by cell-wise colors or cell- or face-wise vector arrows. The module is quite useful for simple visualization purposes. For more advanced visualization, especially in 3d, we recommend exporting the information to vtu using the exporter module found in this folder.

plot_grid(grid, cell_value=None, vector_value=None, info=None, **kwargs)[source]

Plot the (possibly mixed-dimensional) grid with data in a 3d framework.

It is possible to add the cell ids at the cells centers (info option ‘c’), the face ids at the face centers (info option ‘f’), the node ids at the node (info option ‘n’), and the normal at the face (info option ‘o’). If info is set to ‘all’ all the information are displayed.

Parameters
  • grid (pp.Grid or pp.MixedDimensionalGrid) – subdomain or mixed-dimensional grid.

  • cell_value (str or array, optional) – represented (only 1d and 2d). If g is a mixed-dimensional grid the name (key) of the scalar field.

  • vector_value (Optional[Union[ndarray, str]]) – (optional) if g is a single grid then vector scalar field to be represented (only 1d and 2d). If g is a mixed-dimensional grid the name (key) of the vector field.

  • info (Optional[str]) – (optional) add extra information to the plot. C, F, and N add cell, face and node numbers, respectively. O gives a plot of the face normals. See the funtion add_info.

  • kwargs (optional) –

    Keyword arguments: alpha: transparency of cells (2d) and faces (3d) cells: boolean array with length number of cells. Only plot cells c

    where cells[c]=True. Not valid for a MixedDimensionalGrid.

Return type

None

Example: # if grid is a single grid: cell_id = np.arange(grid.num_cells) plot_grid(grid, cell_value=cell_id, info=”ncfo”, alpha=0.75)

# if grid is a mixed-dimensional grid plot_grid(grid, cell_value=”cell_id”, info=”ncfo”, alpha=0.75)

plot_mdg(mdg, cell_value, vector_value, info=None, **kwargs)[source]

Plot a mixed-dimensional grid and selected data.

Parameters
  • mdg (pp.MixedDimensionalGrid) – Mixed-dimensional grid

  • cell_value (str) – key to scalar cell values, will be represented by the color

  • cells. (of the) –

  • vector_value (str) – key to vector cell or face values.

  • info (str, optional) – Which geometry information to display, see add_info.

  • kwargs (optional) –

    Keyword arguments: figsize: Size of figure. color_map: Limits of the cell value color axis. rgb: Color map weights. Defaults to [1, 0, 0]. if_plot: Boolean flag determining whether the plot is shown or not. pointsize: Size of points marking 0d grids. linewidth: Width of faces in 2d and edges in 3d. alpha: Transparency of the plot. cells: boolean array with length number of cells. Only plot cells c

    where cells[c]=True

Return type

None

plot_sd(sd, cell_value, vector_value, info, **kwargs)[source]

Plot data on a subdomain and provided data.

Parameters
  • sd (pp.Grid) – Subdomain

  • cell_value (np.ndarray) – cell-wise scalar values, will be represented by the color

  • cells. (of the) –

  • vector_value (np.ndarray) – vector values, one 3d vector for each cell or for each face (see the _quiver function).

  • info (str, optional) – Which geometry information to display, see add_info.

  • kwargs (optional) –

    Keyword arguments: figsize: Size of figure. color_map: Limits of the cell value color axis. if_plot: Boolean flag determining whether the plot is shown or not. plot_2d: Boolean flag determining wheter the plit is showed in 2d or 3d. pointsize: Size of points marking 0d grids. linewidth: Width of faces in 2d and edges in 3d. rgb: Color map weights. Defaults to [1, 0, 0]. alpha: Transparency of the plot. cells: boolean array with length number of cells. Only plot cells c

    where cells[c]=True

Return type

None

save_img(name, grid, cell_value=None, vector_value=None, info=None, **kwargs)[source]

Plot and save the grid in a 3d framework.

It is possible to add the cell ids at the cells centers (info option ‘c’), the face ids at the face centers (info option ‘f’), the node ids at the node (info option ‘n’), and the normal at the face (info option ‘o’). If info is set to ‘all’ all the informations are displayed.

Parameters
  • name (str) – the name of the file

  • grid (pp.Grid or pp.MixedDimensionalGrid) – subdomain or mixed-dimensional grid.

  • cell_value (array or string, optional) – if g is a single grid then cell scalar field to be represented (only 1d and 2d). If g is a mixed-dimensional grid the name (key) of the scalar field.

  • vector_value (array or string, optional) – if grid is a single grid then vector scalar field to be represented (only 1d and 2d). If grid is a mixed-dimensional grid the name (key) of the vector field.

  • kwargs (optional) – Keyword arguments: info: add extra information to the plot, see plot_grid. alpha: transparency of cells (2d) and faces (3d)

  • info (Optional[str]) –

Return type

None

Example: # if grid is a single grid: cell_id = np.arange(grid.num_cells) save_img(grid, cell_value=cell_id, info=”ncfo”, alpha=0.75)

#if grid is a mixed-dimensional grid save_img(grid, cell_value=”cell_id”, info=”ncfo”, alpha=0.75)