Quanlse/Utils/Plot.py
def plotHeatMap(matrix: numpy.ndarray, xTicks: List = None, yTicks: List = None, xLabel: str = "", yLabel: str = "",
                useLog: bool = False, cMap: str = "cividis") -> None:
    """
    Plot a 2D heat map.

    :param matrix: the values of each square
    :param xTicks: ticks on X axis
    :param yTicks: ticks on Y axis
    :param xLabel: label on X axis
    :param yLabel: label on Y axis
    :param useLog: format ticks on a log scale
    :param cMap: indicate color_map
    :return: None
    """

    ax = plt.gca()

    if useLog:
        _matrix = numpy.log10(matrix)
        im = ax.imshow(_matrix, cmap=cMap, vmin=-10, vmax=0)
    else:
        _matrix = matrix
        im = ax.imshow(_matrix, cmap=cMap)

    for edge, spine in ax.spines.items():
        spine.set_visible(False)

    ax.set_xticks(numpy.arange(numpy.shape(_matrix)[1]))
    ax.set_yticks(numpy.arange(numpy.shape(_matrix)[0]))
    ax.grid(which="minor", color="w", linestyle='-', linewidth=3)
    ax.tick_params(which="minor", bottom=False, left=False)

    if xTicks is None:
        ax.set_xticklabels(numpy.arange(numpy.shape(_matrix)[1]))
    else:
        ax.set_xticklabels(xTicks)

    if yTicks is None:
        ax.set_yticklabels(numpy.arange(numpy.shape(_matrix)[0]))
    else:
        ax.set_yticklabels(yTicks)

    im_ratio = numpy.shape(_matrix)[0] / numpy.shape(_matrix)[1]
    if useLog:
        cbar = ax.figure.colorbar(im, ax=ax, fraction=0.046 * im_ratio, pad=0.04)
        cbar.ax.set_ylabel(r"$\log_{10}(Population)$", rotation=-90, va="bottom")
    else:
        cbar = ax.figure.colorbar(im, ax=ax, fraction=0.046 * im_ratio, pad=0.04)
        cbar.ax.set_ylabel("Population", rotation=-90, va="bottom")

    valFormat = "{x:.2f}"
    threshold = im.norm(numpy.max(_matrix)) / 2.
    textColors = ("black", "white")
    kw = dict(horizontalalignment="center",
              verticalalignment="center")

    for i in range(numpy.shape(_matrix)[0]):
        for j in range(numpy.shape(_matrix)[1]):
            value = float(_matrix[i, j])
            kw.update(color=textColors[int(im.norm(value) < threshold)])
            im.axes.text(j, i, str(round(value, 2)), **kw)

    plt.xlabel(xLabel)
    plt.ylabel(yLabel)
    plt.show()

    Plot a 2D heat map.

    :param matrix: the values of each square
    :param xTicks: ticks on X axis
    :param yTicks: ticks on Y axis
    :param xLabel: label on X axis
    :param yLabel: label on Y axis
    :param useLog: format ticks on a log scale
    :param cMap: indicate color_map
    :return: None
    
Plot a 2D heat map.
Plot a 2D heat map .
def plotHeatMap(matrix: numpy.ndarray, xTicks: List = None, yTicks: List = None, xLabel: str = "", yLabel: str = "",
                useLog: bool = False, cMap: str = "cividis") -> None:
    ax = plt.gca()
    if useLog:
        _matrix = numpy.log10(matrix)
        im = ax.imshow(_matrix, cmap=cMap, vmin=-10, vmax=0)
    else:
        _matrix = matrix
        im = ax.imshow(_matrix, cmap=cMap)
    for edge, spine in ax.spines.items():
        spine.set_visible(False)
    ax.set_xticks(numpy.arange(numpy.shape(_matrix)[1]))
    ax.set_yticks(numpy.arange(numpy.shape(_matrix)[0]))
    ax.grid(which="minor", color="w", linestyle='-', linewidth=3)
    ax.tick_params(which="minor", bottom=False, left=False)
    if xTicks is None:
        ax.set_xticklabels(numpy.arange(numpy.shape(_matrix)[1]))
    else:
        ax.set_xticklabels(xTicks)
    if yTicks is None:
        ax.set_yticklabels(numpy.arange(numpy.shape(_matrix)[0]))
    else:
        ax.set_yticklabels(yTicks)
    im_ratio = numpy.shape(_matrix)[0] / numpy.shape(_matrix)[1]
    if useLog:
        cbar = ax.figure.colorbar(im, ax=ax, fraction=0.046 * im_ratio, pad=0.04)
        cbar.ax.set_ylabel(r"$\log_{10}(Population)$", rotation=-90, va="bottom")
    else:
        cbar = ax.figure.colorbar(im, ax=ax, fraction=0.046 * im_ratio, pad=0.04)
        cbar.ax.set_ylabel("Population", rotation=-90, va="bottom")
    valFormat = "{x:.2f}"
    threshold = im.norm(numpy.max(_matrix)) / 2.
    textColors = ("black", "white")
    kw = dict(horizontalalignment="center",
              verticalalignment="center")
    for i in range(numpy.shape(_matrix)[0]):
        for j in range(numpy.shape(_matrix)[1]):
            value = float(_matrix[i, j])
            kw.update(color=textColors[int(im.norm(value) < threshold)])
            im.axes.text(j, i, str(round(value, 2)), **kw)
    plt.xlabel(xLabel)
    plt.ylabel(yLabel)
    plt.show()
def plotHeatMap ( matrix : numpy . ndarray , xTicks : List = None , yTicks : List = None , xLabel : str = "" , yLabel : str = "" , useLog : bool = False , cMap : str = "cividis" ) -> None : ax = plt . gca ( ) if useLog : _matrix = numpy . log10 ( matrix ) im = ax . imshow ( _matrix , cmap = cMap , vmin = - 10 , vmax = 0 ) else : _matrix = matrix im = ax . imshow ( _matrix , cmap = cMap ) for edge , spine in ax . spines . items ( ) : spine . set_visible ( False ) ax . set_xticks ( numpy . arange ( numpy . shape ( _matrix ) [ 1 ] ) ) ax . set_yticks ( numpy . arange ( numpy . shape ( _matrix ) [ 0 ] ) ) ax . grid ( which = "minor" , color = "w" , linestyle = '-' , linewidth = 3 ) ax . tick_params ( which = "minor" , bottom = False , left = False ) if xTicks is None : ax . set_xticklabels ( numpy . arange ( numpy . shape ( _matrix ) [ 1 ] ) ) else : ax . set_xticklabels ( xTicks ) if yTicks is None : ax . set_yticklabels ( numpy . arange ( numpy . shape ( _matrix ) [ 0 ] ) ) else : ax . set_yticklabels ( yTicks ) im_ratio = numpy . shape ( _matrix ) [ 0 ] / numpy . shape ( _matrix ) [ 1 ] if useLog : cbar = ax . figure . colorbar ( im , ax = ax , fraction = 0.046 * im_ratio , pad = 0.04 ) cbar . ax . set_ylabel ( r"$\log_{10}(Population)$" , rotation = - 90 , va = "bottom" ) else : cbar = ax . figure . colorbar ( im , ax = ax , fraction = 0.046 * im_ratio , pad = 0.04 ) cbar . ax . set_ylabel ( "Population" , rotation = - 90 , va = "bottom" ) valFormat = "{x:.2f}" threshold = im . norm ( numpy . max ( _matrix ) ) / 2. textColors = ( "black" , "white" ) kw = dict ( horizontalalignment = "center" , verticalalignment = "center" ) for i in range ( numpy . shape ( _matrix ) [ 0 ] ) : for j in range ( numpy . shape ( _matrix ) [ 1 ] ) : value = float ( _matrix [ i , j ] ) kw . update ( color = textColors [ int ( im . norm ( value ) < threshold ) ] ) im . axes . text ( j , i , str ( round ( value , 2 ) ) , ** kw ) plt . xlabel ( xLabel ) plt . ylabel ( yLabel ) plt . show ( )
Plot a 2D heat map.
Plot a 2D heat map .
"""
    Plot a 2D heat map.

    :param matrix: the values of each square
    :param xTicks: ticks on X axis
    :param yTicks: ticks on Y axis
    :param xLabel: label on X axis
    :param yLabel: label on Y axis
    :param useLog: format ticks on a log scale
    :param cMap: indicate color_map
    :return: None
    """
None
matrix
numpy.ndarray
the values of each square
the values of each square
xTicks
List
ticks on X axis
ticks on X axis
yTicks
List
ticks on Y axis
ticks on Y axis
xLabel
str
label on X axis
label on X axis
yLabel
str
label on Y axis
label on Y axis
useLog
bool
format ticks on a log scale
format ticks on a log scale
cMap
str
None