def drawSparseMatrix(ax, mat, **kwargs):
    "Draw a view of a matrix into the axes.\n\n    Parameters\n    ----------\n    ax : mpl axis instance, optional\n        Axis instance where the matrix will be plotted.\n\n    mat: pg.matrix.SparseMatrix or pg.matrix.SparseMapMatrix\n\n    Returns\n    -------\n    mpl.lines.line2d\n\n    Examples\n    --------\n    >>> import numpy as np\n    >>> import pygimli as pg\n    >>> from pygimli.viewer.mpl import drawSparseMatrix\n    >>> A = pg.randn((10,10), seed=0)\n    >>> SM = pg.core.SparseMapMatrix()\n    >>> for i in range(10):\n    ...     SM.setVal(i, i, 5.0)\n    >>> fig, (ax1, ax2) = pg.plt.subplots(1, 2, sharey=True, sharex=True)\n    >>> _ = drawSparseMatrix(ax1, A, colOffset=5, rowOffset=5, color='blue')\n    >>> _ = drawSparseMatrix(ax2, SM, color='green')\n    "
    row = kwargs.pop('rowOffset', 0)
    col = kwargs.pop('colOffset', 0)
    color = kwargs.pop('color', None)
    mat = pg.utils.sparseMatrix2coo(mat)
    mat.row += row
    mat.col += col
    gci = ax.spy(mat, color=color)
    ax.autoscale(enable=True, axis='both', tight=True)
    return gci
Draw a view of a matrix into the axes.

Parameters
----------
ax : mpl axis instance, optional
    Axis instance where the matrix will be plotted.

mat: pg.matrix.SparseMatrix or pg.matrix.SparseMapMatrix

Returns
-------
mpl.lines.line2d

Examples
--------
>>> import numpy as np
>>> import pygimli as pg
>>> from pygimli.viewer.mpl import drawSparseMatrix
>>> A = pg.randn((10,10), seed=0)
>>> SM = pg.core.SparseMapMatrix()
>>> for i in range(10):
...     SM.setVal(i, i, 5.0)
>>> fig, (ax1, ax2) = pg.plt.subplots(1, 2, sharey=True, sharex=True)
>>> _ = drawSparseMatrix(ax1, A, colOffset=5, rowOffset=5, color='blue')
>>> _ = drawSparseMatrix(ax2, SM, color='green')
def drawSparseMatrix(ax, mat, **kwargs):
    "Draw a view of a matrix into the axes.\n\n    Parameters\n    ----------\n    ax : mpl axis instance, optional\n        Axis instance where the matrix will be plotted.\n\n    mat: pg.matrix.SparseMatrix or pg.matrix.SparseMapMatrix\n\n    Returns\n    -------\n    mpl.lines.line2d\n\n    Examples\n    --------\n    >>> import numpy as np\n    >>> import pygimli as pg\n    >>> from pygimli.viewer.mpl import drawSparseMatrix\n    >>> A = pg.randn((10,10), seed=0)\n    >>> SM = pg.core.SparseMapMatrix()\n    >>> for i in range(10):\n    ...     SM.setVal(i, i, 5.0)\n    >>> fig, (ax1, ax2) = pg.plt.subplots(1, 2, sharey=True, sharex=True)\n    >>> _ = drawSparseMatrix(ax1, A, colOffset=5, rowOffset=5, color='blue')\n    >>> _ = drawSparseMatrix(ax2, SM, color='green')\n    "
    row = kwargs.pop('rowOffset', 0)
    col = kwargs.pop('colOffset', 0)
    color = kwargs.pop('color', None)
    mat = pg.utils.sparseMatrix2coo(mat)
    mat.row += row
    mat.col += col
    gci = ax.spy(mat, color=color)
    ax.autoscale(enable=True, axis='both', tight=True)
    return gci