def drawBlockMatrix(ax, mat, **kwargs):
    'Draw a view of a matrix into the axes.\n\n    Arguments\n    ---------\n\n    ax : mpl axis instance, optional\n        Axis instance where the matrix will be plotted.\n\n    mat: pg.Matrix.BlockMatrix\n\n    Keyword Arguments\n    -----------------\n    spy: bool [False]\n        Draw all matrix entries instead of colored blocks\n\n    Returns\n    -------\n    ax:\n\n    Examples\n    --------\n    >>> import numpy as np\n    >>> import pygimli as pg\n    >>> I = pg.matrix.IdentityMatrix(10)\n    >>> SM = pg.matrix.SparseMapMatrix()\n    >>> for i in range(10):\n    ...     SM.setVal(i, 10 - i, 5.0)\n    ...     SM.setVal(i,  i, 5.0)\n    >>> B = pg.matrix.BlockMatrix()\n    >>> B.add(I, 0, 0)\n    0\n    >>> B.add(SM, 10, 10)\n    1\n    >>> print(B)\n    pg.matrix.BlockMatrix of size 20 x 21 consisting of 2 submatrices.\n    >>> fig, (ax1, ax2) = pg.plt.subplots(1, 2, sharey=True)\n    >>> _ = pg.show(B, ax=ax1)\n    >>> _ = pg.show(B, spy=True, ax=ax2)\n    '
    if kwargs.pop('spy', False):
        gci = []
        ids = pg.unique([e.matrixID for e in mat.entries()])
        cMap = pg.plt.cm.get_cmap('Set3', len(ids))
        for e in mat.entries():
            mid = e.matrixID
            mati = mat.mat(mid)
            if isinstance(mati, pg.core.IdentityMatrix):
                mati = np.eye(mati.size())
            gci.append(drawSparseMatrix(ax, mati, rowOffset=e.rowStart, colOffset=e.colStart, color=cMap(mid)))
        return (gci, None)
    else:
        plcs = []
        for e in mat.entries():
            mid = e.matrixID
            widthy = (mat.mat(mid).rows() - 0.1)
            widthx = (mat.mat(mid).cols() - 0.1)
            plc = pg.meshtools.createRectangle([e.colStart, e.rowStart], [(e.colStart + widthx), (e.rowStart + widthy)], marker=mid)
            plcs.append(plc)
        bm = pg.meshtools.mergePLC(plcs)
        (gci, cBar) = pg.viewer.mpl.drawPLC(ax, bm, fitView=False)
        ax.invert_yaxis()
        ax.xaxis.tick_top()
        cBar.set_label('Matrix ID')
        if (len(mat.entries()) > 10):
            gci.set_cmap('viridis')
        return (gci, cBar)
Draw a view of a matrix into the axes.

Arguments
---------

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

mat: pg.Matrix.BlockMatrix

Keyword Arguments
-----------------
spy: bool [False]
    Draw all matrix entries instead of colored blocks

Returns
-------
ax:

Examples
--------
>>> import numpy as np
>>> import pygimli as pg
>>> I = pg.matrix.IdentityMatrix(10)
>>> SM = pg.matrix.SparseMapMatrix()
>>> for i in range(10):
...     SM.setVal(i, 10 - i, 5.0)
...     SM.setVal(i,  i, 5.0)
>>> B = pg.matrix.BlockMatrix()
>>> B.add(I, 0, 0)
0
>>> B.add(SM, 10, 10)
1
>>> print(B)
pg.matrix.BlockMatrix of size 20 x 21 consisting of 2 submatrices.
>>> fig, (ax1, ax2) = pg.plt.subplots(1, 2, sharey=True)
>>> _ = pg.show(B, ax=ax1)
>>> _ = pg.show(B, spy=True, ax=ax2)
def drawBlockMatrix(ax, mat, **kwargs):
    'Draw a view of a matrix into the axes.\n\n    Arguments\n    ---------\n\n    ax : mpl axis instance, optional\n        Axis instance where the matrix will be plotted.\n\n    mat: pg.Matrix.BlockMatrix\n\n    Keyword Arguments\n    -----------------\n    spy: bool [False]\n        Draw all matrix entries instead of colored blocks\n\n    Returns\n    -------\n    ax:\n\n    Examples\n    --------\n    >>> import numpy as np\n    >>> import pygimli as pg\n    >>> I = pg.matrix.IdentityMatrix(10)\n    >>> SM = pg.matrix.SparseMapMatrix()\n    >>> for i in range(10):\n    ...     SM.setVal(i, 10 - i, 5.0)\n    ...     SM.setVal(i,  i, 5.0)\n    >>> B = pg.matrix.BlockMatrix()\n    >>> B.add(I, 0, 0)\n    0\n    >>> B.add(SM, 10, 10)\n    1\n    >>> print(B)\n    pg.matrix.BlockMatrix of size 20 x 21 consisting of 2 submatrices.\n    >>> fig, (ax1, ax2) = pg.plt.subplots(1, 2, sharey=True)\n    >>> _ = pg.show(B, ax=ax1)\n    >>> _ = pg.show(B, spy=True, ax=ax2)\n    '
    if kwargs.pop('spy', False):
        gci = []
        ids = pg.unique([e.matrixID for e in mat.entries()])
        cMap = pg.plt.cm.get_cmap('Set3', len(ids))
        for e in mat.entries():
            mid = e.matrixID
            mati = mat.mat(mid)
            if isinstance(mati, pg.core.IdentityMatrix):
                mati = np.eye(mati.size())
            gci.append(drawSparseMatrix(ax, mati, rowOffset=e.rowStart, colOffset=e.colStart, color=cMap(mid)))
        return (gci, None)
    else:
        plcs = []
        for e in mat.entries():
            mid = e.matrixID
            widthy = (mat.mat(mid).rows() - 0.1)
            widthx = (mat.mat(mid).cols() - 0.1)
            plc = pg.meshtools.createRectangle([e.colStart, e.rowStart], [(e.colStart + widthx), (e.rowStart + widthy)], marker=mid)
            plcs.append(plc)
        bm = pg.meshtools.mergePLC(plcs)
        (gci, cBar) = pg.viewer.mpl.drawPLC(ax, bm, fitView=False)
        ax.invert_yaxis()
        ax.xaxis.tick_top()
        cBar.set_label('Matrix ID')
        if (len(mat.entries()) > 10):
            gci.set_cmap('viridis')
        return (gci, cBar)