Exemplo n.º 1
0
def plot(workspace, tokens=None):
    """When called from window.py it initiates rendering of equations.

    Arguments:
        workspace {QtWidgets.QWidget} -- main layout
    """
    from visma.io.tokenize import tokenizer

    workspace.figure2D.clear()
    workspace.figure3D.clear()
    if tokens is None:
        tokens = workspace.eqToks[-1]
    eqType = getTokensType(tokens)
    LHStok, RHStok = getLHSandRHS(tokens)
    variables = sorted(getVariables(LHStok, RHStok))
    dim = len(variables)
    graphVars, func, variables = graphPlot(workspace, False, tokens)
    renderPlot(workspace, graphVars, func, variables, tokens)
    if (dim == 1):
        var2, var3 = selectAdditionalVariable(variables[0])
        if tokens is None:
            workspace.eqToks[-1] += tokenizer("0" + var2 + "+" + "0" + var3)
        else:
            tokens += tokenizer("0" + var2 + "+" + "0" + var3)
    if (((dim == 2) or (dim == 1)) & (eqType == 'equation')):
        graphVars, func, variables = graphPlot(workspace, True, tokens)
        renderPlot(workspace, graphVars, func, variables, tokens)
Exemplo n.º 2
0
def graphPlot(workspace):
    """Function for plotting graphs in 2D and 3D space

    2D graphs are plotted for expression in one variable and equations in two variables. 3D graphs are plotted for expressions in two variables and equations in three variables.

    Arguments:
        workspace {QtWidgets.QWidget} -- main layout

    Returns:
        graphVars {list} -- variables to be plotted on the graph
        func {numpy.array(2D)/function(3D)} -- equation converted to compatible data type for plotting
        variables {list} -- variables in given equation

    Note:
        The func obtained from graphPlot() funtion is of different type for 2D and 3D plots. For 2D, func is a numpy array, and for 3D, func is a function.
    """
    tokens = workspace.eqToks[-1]
    axisRange = workspace.axisRange
    eqType = getTokensType(tokens)
    LHStok, RHStok = getLHSandRHS(tokens)
    variables = sorted(getVariables(LHStok, RHStok))
    dim = len(variables)
    if (dim == 1 and eqType == "expression") or ((dim == 2)
                                                 and eqType == "equation"):
        graphVars, func = plotIn2D(LHStok, RHStok, variables, axisRange)
        if dim == 1:
            variables.append('f(' + variables[0] + ')')
    elif (dim == 2 and eqType == "expression") or ((dim == 3)
                                                   and eqType == "equation"):
        graphVars, func = plotIn3D(LHStok, RHStok, variables, axisRange)
        if dim == 2:
            variables.append('f(' + variables[0] + ',' + variables[1] + ')')
    else:
        return [], None, None
    return graphVars, func, variables
Exemplo n.º 3
0
def plot(workspace):
    """When called from window.py it initiates rendering of equations.

    Arguments:
        workspace {QtWidgets.QWidget} -- main layout
    """
    workspace.figure2D.clear()
    workspace.figure3D.clear()

    tokens = workspace.eqToks[-1]
    eqType = getTokensType(tokens)
    LHStok, RHStok = getLHSandRHS(tokens)
    variables = sorted(getVariables(LHStok, RHStok))
    dim = len(variables)

    graphVars, func, variables = graphPlot(workspace, False)
    renderPlot(workspace, graphVars, func, variables)

    # Handles case when a equation (like x^2 + y^2 = 5) can be rendered in 2D as well as 3D.
    if ((dim == 2) and eqType == "equation"):
        graphVars, func, variables = graphPlot(workspace, True)
        renderPlot(workspace, graphVars, func, variables)