Quanlse/Utils/Plot.py
def plotLineGraph(x: Union[List[List[float]], List[float]], y: Union[List[List[float]], List[float]], title: str = "",
                  xLabel: str = "", yLabel: str = "",
                  legends: List[str] = None, color: List[str] = None,
                  lineWidth: float = 2.0,
                  fontSize: float = 10, spacing: float = 0.05, log=False) \
        -> None:
    """
    Plot line graph, with the given 2-dimensional lists of X and Y values,
    this function also supports other optional parameters as shown below.

    :param x: a 2-dim list of X coordinates for the line graphs
    :param y: a 2-dim list of Y coordinates for the line graphs
    :param title: overall title of the graph
    :param xLabel: label on X axis
    :param yLabel: label on Y axis
    :param legends: a list of strings - a label each string
    :param color: a list of colors - a color for each line (unspecified lines will be of default color)
        (from mint, blue, red, green, yellow, black, pink, cyan, purple, darkred, orange, brown, pink and teal)
    :param lineWidth: line width index
    :param fontSize: font size index
    :param spacing: vertical spacing index
    :param log: log, default at false
    :return: None
    """

    # Default color theme
    if color is None:
        color = ['blue', 'pink', 'cyan', 'mint', 'red']

    # take log
    if log:
        tmp = y
        y = numpy.log(numpy.array(y))
        if y.min() == -numpy.Infinity:
            y = tmp
            print("can't take log of zero, switch back to non-log mode")
    # Define Color Map
    cMap = colorMap()

    # Set graph size and background color
    plt.rcParams["figure.figsize"] = (8, 6)
    plt.rcParams['axes.linewidth'] = lineWidth * 0.75

    # Check the type of the input of x and y
    if not isinstance(x[0], list):
        x = [x]
        y = [y]

    # Create figure instance
    plt.figure(1, (15, 10))

    # find max and min for spacing purposes
    maximumX = max(x[0])
    minimumX = min(x[0])
    maximumY = max(y[0])
    minimumY = min(y[0])

    # plot and look for global min/max
    for i in range(0, len(x)):
        if max(y[i]) > maximumY:
            maximumY = max(y[i])
        if min(y[i]) < minimumY:
            minimumY = min(y[i])
        if max(x[i]) > maximumX:
            maximumX = max(x[i])
        if min(x[i]) < minimumX:
            minimumX = min(x[i])

        if (color is None) or (i < 0) or (i >= len(color)):
            if legends is not None:
                plt.plot(x[i], y[i], label=legends[i], linewidth=lineWidth, alpha=1)
            else:
                plt.plot(x[i], y[i], linewidth=lineWidth)
        else:
            flag = False
            for aColor in cMap:
                if aColor[0] == color[i]:
                    flag = True
                    if legends is not None:
                        plt.plot(x[i], y[i], color=aColor[1], linewidth=lineWidth, label=legends[i], alpha=1)
                    else:
                        plt.plot(x[i], y[i], color=aColor[1], linewidth=lineWidth, alpha=1)
            if flag is False:
                raise ValueError('Color not found!')

    # spacing
    plt.xlim([minimumX - (maximumX - minimumX) * spacing, maximumX + (maximumX - minimumY) * spacing])
    plt.ylim([minimumY - (maximumY - minimumY) * spacing, maximumY + (maximumY - minimumY) * spacing])

    # Ticks size
    plt.xticks(fontsize=fontSize, weight='bold')
    plt.yticks(fontsize=fontSize, weight='bold')

    # title and size
    if title is not None:
        plt.title(title, size=int(fontSize * 1.9), weight='bold')

    # label and size
    if xLabel is not None:
        plt.xlabel(xLabel, size=int(fontSize * 1.4), weight='bold')
    if yLabel is not None:
        plt.ylabel(yLabel, size=int(fontSize * 1.4), weight='bold')

    plt.legend()
    plt.show()

    Plot line graph, with the given 2-dimensional lists of X and Y values,
    this function also supports other optional parameters as shown below.

    :param x: a 2-dim list of X coordinates for the line graphs
    :param y: a 2-dim list of Y coordinates for the line graphs
    :param title: overall title of the graph
    :param xLabel: label on X axis
    :param yLabel: label on Y axis
    :param legends: a list of strings - a label each string
    :param color: a list of colors - a color for each line (unspecified lines will be of default color)
        (from mint, blue, red, green, yellow, black, pink, cyan, purple, darkred, orange, brown, pink and teal)
    :param lineWidth: line width index
    :param fontSize: font size index
    :param spacing: vertical spacing index
    :param log: log, default at false
    :return: None
    
Plot line graph, with the given 2-dimensional lists of X and Y values,
this function also supports other optional parameters as shown below.
Plot line graph with the given 2 - dimensional lists of X and Y values this function also supports other optional parameters as shown below .
def plotLineGraph(x: Union[List[List[float]], List[float]], y: Union[List[List[float]], List[float]], title: str = "",
                  xLabel: str = "", yLabel: str = "",
                  legends: List[str] = None, color: List[str] = None,
                  lineWidth: float = 2.0,
                  fontSize: float = 10, spacing: float = 0.05, log=False) \
        -> None:
    if color is None:
        color = ['blue', 'pink', 'cyan', 'mint', 'red']
    if log:
        tmp = y
        y = numpy.log(numpy.array(y))
        if y.min() == -numpy.Infinity:
            y = tmp
            print("can't take log of zero, switch back to non-log mode")
    cMap = colorMap()
    plt.rcParams["figure.figsize"] = (8, 6)
    plt.rcParams['axes.linewidth'] = lineWidth * 0.75
    if not isinstance(x[0], list):
        x = [x]
        y = [y]
    plt.figure(1, (15, 10))
    maximumX = max(x[0])
    minimumX = min(x[0])
    maximumY = max(y[0])
    minimumY = min(y[0])
    for i in range(0, len(x)):
        if max(y[i]) > maximumY:
            maximumY = max(y[i])
        if min(y[i]) < minimumY:
            minimumY = min(y[i])
        if max(x[i]) > maximumX:
            maximumX = max(x[i])
        if min(x[i]) < minimumX:
            minimumX = min(x[i])
        if (color is None) or (i < 0) or (i >= len(color)):
            if legends is not None:
                plt.plot(x[i], y[i], label=legends[i], linewidth=lineWidth, alpha=1)
            else:
                plt.plot(x[i], y[i], linewidth=lineWidth)
        else:
            flag = False
            for aColor in cMap:
                if aColor[0] == color[i]:
                    flag = True
                    if legends is not None:
                        plt.plot(x[i], y[i], color=aColor[1], linewidth=lineWidth, label=legends[i], alpha=1)
                    else:
                        plt.plot(x[i], y[i], color=aColor[1], linewidth=lineWidth, alpha=1)
            if flag is False:
                raise ValueError('Color not found!')
    plt.xlim([minimumX - (maximumX - minimumX) * spacing, maximumX + (maximumX - minimumY) * spacing])
    plt.ylim([minimumY - (maximumY - minimumY) * spacing, maximumY + (maximumY - minimumY) * spacing])
    plt.xticks(fontsize=fontSize, weight='bold')
    plt.yticks(fontsize=fontSize, weight='bold')
    if title is not None:
        plt.title(title, size=int(fontSize * 1.9), weight='bold')
    if xLabel is not None:
        plt.xlabel(xLabel, size=int(fontSize * 1.4), weight='bold')
    if yLabel is not None:
        plt.ylabel(yLabel, size=int(fontSize * 1.4), weight='bold')
    plt.legend()
    plt.show()
def plotLineGraph ( x : Union [ List [ List [ float ] ] , List [ float ] ] , y : Union [ List [ List [ float ] ] , List [ float ] ] , title : str = "" , xLabel : str = "" , yLabel : str = "" , legends : List [ str ] = None , color : List [ str ] = None , lineWidth : float = 2.0 , fontSize : float = 10 , spacing : float = 0.05 , log = False ) -> None : if color is None : color = [ 'blue' , 'pink' , 'cyan' , 'mint' , 'red' ] if log : tmp = y y = numpy . log ( numpy . array ( y ) ) if y . min ( ) == - numpy . Infinity : y = tmp print ( "can't take log of zero, switch back to non-log mode" ) cMap = colorMap ( ) plt . rcParams [ "figure.figsize" ] = ( 8 , 6 ) plt . rcParams [ 'axes.linewidth' ] = lineWidth * 0.75 if not isinstance ( x [ 0 ] , list ) : x = [ x ] y = [ y ] plt . figure ( 1 , ( 15 , 10 ) ) maximumX = max ( x [ 0 ] ) minimumX = min ( x [ 0 ] ) maximumY = max ( y [ 0 ] ) minimumY = min ( y [ 0 ] ) for i in range ( 0 , len ( x ) ) : if max ( y [ i ] ) > maximumY : maximumY = max ( y [ i ] ) if min ( y [ i ] ) < minimumY : minimumY = min ( y [ i ] ) if max ( x [ i ] ) > maximumX : maximumX = max ( x [ i ] ) if min ( x [ i ] ) < minimumX : minimumX = min ( x [ i ] ) if ( color is None ) or ( i < 0 ) or ( i >= len ( color ) ) : if legends is not None : plt . plot ( x [ i ] , y [ i ] , label = legends [ i ] , linewidth = lineWidth , alpha = 1 ) else : plt . plot ( x [ i ] , y [ i ] , linewidth = lineWidth ) else : flag = False for aColor in cMap : if aColor [ 0 ] == color [ i ] : flag = True if legends is not None : plt . plot ( x [ i ] , y [ i ] , color = aColor [ 1 ] , linewidth = lineWidth , label = legends [ i ] , alpha = 1 ) else : plt . plot ( x [ i ] , y [ i ] , color = aColor [ 1 ] , linewidth = lineWidth , alpha = 1 ) if flag is False : raise ValueError ( 'Color not found!' ) plt . xlim ( [ minimumX - ( maximumX - minimumX ) * spacing , maximumX + ( maximumX - minimumY ) * spacing ] ) plt . ylim ( [ minimumY - ( maximumY - minimumY ) * spacing , maximumY + ( maximumY - minimumY ) * spacing ] ) plt . xticks ( fontsize = fontSize , weight = 'bold' ) plt . yticks ( fontsize = fontSize , weight = 'bold' ) if title is not None : plt . title ( title , size = int ( fontSize * 1.9 ) , weight = 'bold' ) if xLabel is not None : plt . xlabel ( xLabel , size = int ( fontSize * 1.4 ) , weight = 'bold' ) if yLabel is not None : plt . ylabel ( yLabel , size = int ( fontSize * 1.4 ) , weight = 'bold' ) plt . legend ( ) plt . show ( )
Plot line graph, with the given 2-dimensional lists of X and Y values,
this function also supports other optional parameters as shown below.
Plot line graph with the given 2 - dimensional lists of X and Y values this function also supports other optional parameters as shown below .
"""
    Plot line graph, with the given 2-dimensional lists of X and Y values,
    this function also supports other optional parameters as shown below.

    :param x: a 2-dim list of X coordinates for the line graphs
    :param y: a 2-dim list of Y coordinates for the line graphs
    :param title: overall title of the graph
    :param xLabel: label on X axis
    :param yLabel: label on Y axis
    :param legends: a list of strings - a label each string
    :param color: a list of colors - a color for each line (unspecified lines will be of default color)
        (from mint, blue, red, green, yellow, black, pink, cyan, purple, darkred, orange, brown, pink and teal)
    :param lineWidth: line width index
    :param fontSize: font size index
    :param spacing: vertical spacing index
    :param log: log, default at false
    :return: None
    """ # Default color theme # take log # Define Color Map # Set graph size and background color # Check the type of the input of x and y # Create figure instance # find max and min for spacing purposes # plot and look for global min/max # spacing # Ticks size # title and size # label and size
None
x
Union[List[List[float]], List[float]]
a 2-dim list of X coordinates for the line graphs
a 2 - dim list of X coordinates for the line graphs
y
Union[List[List[float]], List[float]]
a 2-dim list of Y coordinates for the line graphs
a 2 - dim list of Y coordinates for the line graphs
title
str
overall title of the graph
overall title of the graph
xLabel
str
label on X axis
label on X axis
yLabel
str
label on Y axis
label on Y axis
legends
List[str]
a list of strings - a label each string
a list of strings - a label each string
color
List[str]
a list of colors - a color for each line (unspecified lines will be of default color)
(from mint, blue, red, green, yellow, black, pink, cyan, purple, darkred, orange, brown, pink and teal)
a list of colors - a color for each line ( unspecified lines will be of default color ) ( from mint blue red green yellow black pink cyan purple darkred orange brown pink and teal )
lineWidth
float
line width index
line width index
fontSize
float
font size index
font size index
spacing
float
vertical spacing index
vertical spacing index
log
log, default at false
log default at false