sgio.plot_matrix#

sgio.plot_matrix(matrix, fig=None, ax=None, row_labels: Sequence[str] | None = None, col_labels: Sequence[str] | None = None, cmap: str = 'RdBu_r', annotate: bool = True, font_size: int = 8, symlog: bool = True, vmin: float | None = None, vmax: float | None = None, linthresh: float | None = None, **kwargs)#

Plot a heatmap of an arbitrary 2D matrix.

By default the color scale is centered on 0 and symmetric (vmin = -vmax), so a diverging colormap places the neutral color at zero and mirrors the sign of each entry. It defaults to a symmetric-log (SymLogNorm) mapping so that entries spanning several orders of magnitude – typical of stiffness / compliance matrices – remain simultaneously legible.

The color range can be overridden with vmin / vmax. Passing only one of them mirrors it to the opposite sign so the scale stays symmetric; passing both uses them verbatim (which may be asymmetric).

Parameters:
  • matrix (array_like) – A 2D array (n_rows x n_cols) to visualize.

  • fig (matplotlib.figure.Figure) – Figure used to attach the colorbar.

  • ax (matplotlib.axes.Axes) – Axes to plot on.

  • row_labels (sequence of str, optional) – Tick labels for the rows. Defaults to 1 .. n_rows.

  • col_labels (sequence of str, optional) – Tick labels for the columns. Defaults to 1 .. n_cols.

  • cmap (str, optional) – Colormap name. Default 'coolwarm' (diverging, neutral at 0).

  • annotate (bool, optional) – Whether to annotate each cell with its value. Default True.

  • font_size (int, optional) – Font size for the annotations. Default 8.

  • symlog (bool, optional) – Use a symmetric-log color scale. When False a linear scale is used. Default True.

  • vmin (float, optional) – Lower / upper bounds of the color scale. When both are None the scale spans [-max(|matrix|), +max(|matrix|)]. When only one is given, the other defaults to its negation (symmetric scale).

  • vmax (float, optional) – Lower / upper bounds of the color scale. When both are None the scale spans [-max(|matrix|), +max(|matrix|)]. When only one is given, the other defaults to its negation (symmetric scale).

  • linthresh (float, optional) – Half-width of the linear region around 0 for the symmetric-log scale. Only used when symlog is True. Defaults to the smallest nonzero absolute entry of the matrix. Must be positive.

  • **kwargs – Extra keyword arguments forwarded to ax.matshow.

Returns:

The heatmap image object.

Return type:

matplotlib.image.AxesImage