Exemplo n.º 1
0
def RenderAnyFunction(xleft,xright,ybot,ytop,functionLatex,functionExpr):
    
    deltaxStr = '(' + str(xright) + "-" + str(xleft) + ')/10'
    deltayStr = '(' + str(ytop) + "-" + str(ybot) + ')/10'
    detalx = parse_expr(deltaxStr).evalf()
    if (detalx < 0.5):
        detalx = 0.5
    else:
        detalx = int(round(parse_expr(deltaxStr).evalf()))
    detaly = parse_expr(deltayStr).evalf()
    if (detaly < 0.5):
        detaly = 0.5
    else:
        detaly = int(round(parse_expr(deltayStr).evalf()))
    tex =  '\\documentclass[preview]{standalone}'
    tex += '\\usepackage[hmargin = 0cm, vmargin = 0cm]{geometry}'
    tex += '\\usepackage{tikz}'
    tex += '\\usepackage{pgfplots}'
    tex += '\\begin{document}'
    tex += '\\begin{figure}[h!tbp]'
    tex += '\\centering'
    tex += '\\begin{tikzpicture}'
    tex += '\\begin{axis}['
    tex += 'height = 15cm,'
    tex += 'domain=' + str(xleft) + ':' + str(xright) +','
    tex += 'grid = major,'
    tex += 'grid style = {dashed, gray!50},'
    tex += 'axis lines = middle,'
    tex += 'inner axis line style = {= >},'
    tex += 'xlabel = {\\large $x$},'
    tex += 'ylabel = {\\large $y$},'
    tex += 'yticklabel style = {inner ysep = 0pt, anchor = south east},'
    tex += 'xticklabel style= {inner xsep = 0pt, anchor = north west},'
    tex += 'xtick = {'
    tex += str(xleft) + ',' + str(xleft + detalx) + ', ..., ' + str(xright) + '},'
    tex += 'ytick = {'
    tex += str(ybot) + ',' + str(ybot + detaly) + ', ..., ' + str(ytop) + '},'
    tex += 'ymin = ' + str(ybot - detaly) + ','
    tex += 'ymax = ' + str(ytop + detaly) + ','
    tex += 'xmin = ' + str(xleft - detalx) + ','
    tex += 'xmax = ' + str(xright + detalx) + ','
    tex += 'after end axis/.code = {\\path (axis cs: 0,0) node [anchor = north west, yshift = -0.075cm] {0};}]'
    tex += '\\addplot[color = red, thick, domain=' + str(xleft) +':' + str(xright) + ',restrict y to domain =' + str(ybot) + ':'+ str(ytop) + ',samples = 201] {' + functionExpr + '};'
    tex += '\\legend{$\\displaystyle ' + functionLatex + '$}'
    tex += '\\end{axis}'
    tex += '\\end{tikzpicture}'
    tex +='\\end{figure}'
    tex += '\\end{document}'
    return  tex2base64(tex)
Exemplo n.º 2
0
def RenderTexQuadRationalLinear(arr_fig, xleft, xright, ytop, ybot,
                                functionLatex):
    a = arr_fig[0]
    b = arr_fig[1]
    c = arr_fig[2]
    d = arr_fig[3]
    e = arr_fig[4]
    alpha = arr_fig[5]
    beta = arr_fig[6]
    tcn = a / c
    tcd = -d / c

    Ix = -e / d
    Iy = alpha * Ix + beta
    if (Ix < 0):
        xleft = int(floor(xleft)) - 2 * abs(Ix)
        xright = int(ceiling(xright)) + abs(Ix)
    else:
        xleft = int(floor(xleft)) - abs(Ix)
        xright = int(ceiling(xright)) + 2 * abs(Ix)
    ytop = int(ceiling(ytop)) + abs(2 * Iy)
    ybot = int(floor(ybot)) - abs(2 * Iy)
    if (ybot > -2):
        ybot = -2

    if (ytop < 2):
        ytop = 2

    if xleft > -2:
        xleft = -2
    if xright < 2:
        xright = 2

    deltaxStr = '(' + str(xright) + "-" + str(xleft) + ')/10'
    deltayStr = '(' + str(ytop) + "-" + str(ybot) + ')/10'
    detalx = parse_expr(deltaxStr).evalf(3)
    if (detalx < 0.5):
        detalx = 0.5
    else:
        detalx = int(round(parse_expr(deltaxStr).evalf(3)))
    detaly = parse_expr(deltayStr).evalf(3)
    if (detaly < 0.5):
        detaly = 0.5
    else:
        detaly = int(round(parse_expr(deltayStr).evalf(3)))
    tex = '\\documentclass[preview]{standalone}'
    tex += '\\usepackage[hmargin = 0cm, vmargin = 0cm]{geometry}'
    tex += '\\usepackage{tikz}'
    tex += '\\usepackage{pgfplots}'
    tex += '\\begin{document}'
    tex += '\\begin{figure}[h!tbp]'
    tex += '\\centering'
    tex += '\\begin{tikzpicture}'
    tex += '\\begin{axis}['
    tex += 'height = 15cm,'
    tex += 'domain=' + str(xleft) + ':' + str(xright) + ','
    tex += 'grid = major,'
    tex += 'grid style = {dashed, gray!50},'
    tex += 'axis lines = middle,'
    tex += 'inner axis line style = {= >},'
    tex += 'xlabel = {\\large $x$},'
    tex += 'ylabel = {\\large $y$},'
    tex += 'yticklabel style = {inner ysep = 0pt, anchor = south east},'
    tex += 'xticklabel style= {inner xsep = 0pt, anchor = north west},'
    tex += 'xtick = {'
    tex += str(xleft) + ',' + str(xleft +
                                  detalx) + ', ..., ' + str(xright) + '},'
    tex += 'ytick = {'
    tex += str(ybot) + ',' + str(ybot + detaly) + ', ..., ' + str(ytop) + '},'
    tex += 'ymin = ' + str(ybot - detaly) + ','
    tex += 'ymax = ' + str(ytop + detaly) + ','
    tex += 'xmin = ' + str(xleft - detalx) + ','
    tex += 'xmax = ' + str(xright + detalx) + ','
    tex += 'after end axis/.code = {\\path (axis cs: 0,0) node [anchor = north west, yshift = -0.075cm] {0};}]'
    tex += 'after end axis/.code = {\\path (axis cs: ' + str(Ix) + ',' + str(
        Iy
    ) + ') node [anchor = south west, yshift = -0.075cm, xshift = 0.075cm] {I};}]'
    tex += '\\addplot[color = red, thick, samples = 201] {(' + str(
        a) + '*x*x + ' + str(b) + '*x+' + str(c) + ')/(' + str(
            d) + '*x+' + str(e) + ')};'
    tex += '\\legend{$' + functionLatex + '$}'
    tex += '\\addplot[scatter, only marks,scatter src = explicit symbolic]'
    tex += 'coordinates {(' + str(Ix) + ',' + str(Iy) + ')[a]};'
    tex += '\\addplot[color = red, thick, samples = 201] {' + str(
        alpha) + '*x+' + str(beta) + '};'
    tex += '\\end{axis}'
    tex += '\\end{tikzpicture}'
    tex += '\\end{figure}'
    tex += '\\end{document}'
    return tex2base64(tex)
Exemplo n.º 3
0
def RenderTexLinear(a,b,functionLatex):
    x = parse_expr('-' + '(' + b + ')' + '/' + '(' + a + ')')
    xright = xleft = int(round(abs(x.evalf()))) + 2
    ytop = ybot = int(round(abs(parse_expr(b).evalf()))) + 2
    # if (xright < 3):
    #     xright = xleft = 4
    # if (ytop < 3):
    #     ytop = ybot = 4

    deltaxStr = '(' + str(xright) + "+" + str(xleft) + ')/10'
    deltayStr = '(' + str(ytop) + "+" + str(ybot) + ')/10'
    detalx = parse_expr(deltaxStr).evalf()
    if (detalx < 0.5):
        detalx = 0.5
    else:
        detalx = int(round(parse_expr(deltaxStr).evalf()))
    detaly = parse_expr(deltayStr).evalf()
    if (detaly < 0.5):
        detaly = 0.5
    else:
        detaly = int(round(parse_expr(deltayStr).evalf()))
    tex =  '\\documentclass[preview]{standalone}'
    tex += '\\usepackage[hmargin = 0cm, vmargin = 0cm]{geometry}'
    tex += '\\usepackage{tikz}'
    tex += '\\usepackage{pgfplots}'
    tex += '\\begin{document}'
    tex += '\\begin{figure}[h!tbp]'
    tex += '\\centering'
    tex += '\\begin{tikzpicture}'
    tex += '\\begin{axis}['
    tex += 'scatter / classes = {a = {mark = square *, blue}},'
    tex += 'height = 15cm,'
    tex += 'domain=-' + str(xleft) + ':' + str(xright) +','
    tex += 'grid = major,'
    tex += 'grid style = {dashed, gray!50},'
    tex += 'axis lines = middle,'
    tex += 'inner axis line style = {= >},'
    tex += 'xlabel = {\\large $x$},'
    tex += 'ylabel = {\\large $y$},'
    tex += 'yticklabel style = {inner ysep = 0pt, anchor = south east},'
    tex += 'xticklabel style= {inner xsep = 0pt, anchor = north west},'
    tex += 'xtick = {-'
    tex += str(xleft) + ',-' + str(xleft - detalx) + ', ..., ' + str(xright) + '},'
    tex += 'ytick = {-'
    tex += str(ybot) + ',-' + str(ybot - detaly) + ', ..., ' + str(ytop) + '},'
    tex += 'ymin = ' + str(-ybot - detaly) + ','
    tex += 'ymax = ' + str(ytop + detaly) + ','
    tex += 'xmin = ' + str(-xleft - detalx) + ','
    tex += 'xmax = ' + str(xright + detalx) + ','
    tex += 'after end axis/.code = {\\path (axis cs: 0,0) node [anchor = north west, yshift = -0.075cm] {0};}]'
    tex += 'after end axis/.code = {\\path (axis cs: 0,' + str(b) + ') node [anchor = south west, yshift = 0.075cm, xshift = 0.075cm] {B};}]'
    tex += 'after end axis/.code = {\\path (axis cs: '+ str(x)+ ',0) node [anchor = south west, yshift = 0.075cm, xshift = 0.075cm] {A};}]'
    tex += '\\addplot[color = red, thick, samples = 50] {' + str(a) + '*x + ' + str(b) +'};' 
    tex += '\\legend{$\\displaystyle ' + functionLatex + '$}'
    tex += '\\addplot[scatter, only marks,scatter src = explicit symbolic]'
    tex += 'coordinates {(0, ' + str(b) + ')[a]('+str(x)+',0)[a] };'
    tex += '\\end{axis}'
    tex += '\\end{tikzpicture}'
    tex +='\\end{figure}'
    tex += '\\end{document}'
    return tex2base64(tex)
Exemplo n.º 4
0
def RenderTexQuad(arr_fig, point, delta, y, functionLatex):
    a = parse_expr(arr_fig[0]).evalf(3)
    b = parse_expr(arr_fig[1]).evalf(3)
    c = parse_expr(arr_fig[2]).evalf(4)
    xleft = int(round(point[0] - delta - 1 - abs(c) / 4))
    xright = int(round(point[0] + delta + 1 + abs(c) / 4))

    if xleft > -2:
        xleft = -2
    if xright < 2:
        xright = 2

    if (Mod(xleft, 2)) != 0:
        xleft += -1

    if (Mod(xright, 2)) != 0:
        xright += 1

    if a > 0:
        ybot = int(floor(point[1]))
        if (Mod(ybot, 2)) != 0:
            ybot = ybot - 1
        ytop = int(ceiling(y))
        if (Mod(ytop, 2)) != 0:
            ytop = ytop + 1
        if (ybot > -2):
            ybot = -2

        if (ytop < 2):
            ytop = 2

    else:
        ybot = int(floor(y))
        if (Mod(ybot, 2)) != 0:
            ybot = ybot - 1
        ytop = int(ceiling(point[1]))
        if (Mod(ytop, 2)) != 0:
            ytop = ytop + 1
        if (ybot > -2):
            ybot = -2

        if (ytop < 2):
            ytop = 2

    deltaxStr = '(' + str(xright) + "-" + str(xleft) + ')/10'
    deltayStr = '(' + str(ytop) + "-" + str(ybot) + ')/10'
    detalx = parse_expr(deltaxStr).evalf()
    if (detalx < 0.5):
        detalx = 0.5
    else:
        detalx = int(round(parse_expr(deltaxStr).evalf()))
    detaly = parse_expr(deltayStr).evalf()
    if (detaly < 0.5):
        detaly = 0.5
    else:
        detaly = int(round(parse_expr(deltayStr).evalf()))
    xleft = parse_expr(str(xleft)).evalf(4)
    xright = parse_expr(str(xright)).evalf(4)
    ytop = parse_expr(str(ytop)).evalf(4)
    ybot = parse_expr(str(ybot)).evalf(4)
    point[0] = parse_expr(str(point[0])).evalf(4)
    point[1] = parse_expr(str(point[1])).evalf(4)
    tex = '\\documentclass[preview]{standalone}'
    tex += '\\usepackage[hmargin = 0cm, vmargin = 0cm]{geometry}'
    tex += '\\usepackage{tikz}'
    tex += '\\usepackage{pgfplots}'
    tex += '\\begin{document}'
    tex += '\\begin{figure}[h!tbp]'
    tex += '\\centering'
    tex += '\\begin{tikzpicture}'
    tex += '\\begin{axis}['
    tex += 'scatter / classes = {a = {mark = square *, blue}},'
    tex += 'height = 15cm,'
    tex += 'domain=' + str(point[0] - (delta - 1) -
                           0.1) + ':' + str(point[0] + (delta - 1) + 0.1) + ','
    tex += 'grid = major,'
    tex += 'grid style = {dashed, gray!50},'
    tex += 'axis lines = middle,'
    tex += 'inner axis line style = {= >},'
    tex += 'xlabel = {\\large $x$},'
    tex += 'ylabel = {\\large $y$},'
    tex += 'yticklabel style = {inner ysep = 0pt, anchor = south east},'
    tex += 'xticklabel style= {inner xsep = 0pt, anchor = north west},'
    tex += 'xtick = {'
    tex += str(xleft) + ',' + str(xleft +
                                  detalx) + ', ..., ' + str(xright) + '},'
    tex += 'ytick = {'
    tex += str(ybot) + ',' + str(ybot + detaly) + ', ..., ' + str(ytop) + '},'
    tex += 'ymin = ' + str(ybot - detaly) + ','
    tex += 'ymax = ' + str(ytop + detaly) + ','
    tex += 'xmin = ' + str(xleft - detalx) + ','
    tex += 'xmax = ' + str(xright + detalx) + ','
    tex += 'after end axis/.code = {\\path (axis cs: 0,0) node [anchor = north west, yshift = -0.075cm] {0};}]'
    tex += 'after end axis/.code = {\\path (axis cs: ' + str(
        point[0]) + ', ' + str(
            point[1]
        ) + ') node [anchor = south west, yshift = 0.075cm, red] {I};}]'
    tex += '\\addplot[color = red, thick, samples = 201] {' + str(
        a) + '*x*x + ' + str(b) + '*x+' + str(c) + '};'
    tex += '\\legend{$' + functionLatex + '$}'
    tex += '\\addplot[scatter, only marks,scatter src = explicit symbolic]'
    tex += 'coordinates {(' + str(point[0]) + ', ' + str(point[1]) + ')[a] };'
    tex += '\\end{axis}'
    tex += '\\end{tikzpicture}'
    tex += '\\end{figure}'
    tex += '\\end{document}'

    return tex2base64(tex)
Exemplo n.º 5
0
def RenderTexCubic(arr_fig,xleft,xright,ytop,ybot,delta,functionLatex,arr_x,arr_y):
    a = arr_fig[0]
    b = arr_fig[1]
    c = arr_fig[2]
    d = arr_fig[3]

    xleft = int(floor(xleft))
    xright  = int(ceiling(xright))
    ytop = int(ceiling(ytop))
    ybot = int(floor(ybot))
    if (ybot > -2):
        ybot = -2

    if (ytop < 2):
        ytop = 2
    
    if xleft > -2 :
        xleft = -2
    if xright < 2:
        xright = 2

    deltaxStr = '(' + str(xright) + "-" + str(xleft) + ')/10'
    deltayStr = '(' + str(ytop) + "-" + str(ybot) + ')/10'
    detalx = parse_expr(deltaxStr).evalf()
    if (detalx < 0.5):
        detalx = 0.5
    else:
        detalx = int(round(parse_expr(deltaxStr).evalf()))
    detaly = parse_expr(deltayStr).evalf()
    if (detaly < 0.5):
        detaly = 0.5
    else:
        detaly = int(round(parse_expr(deltayStr).evalf()))
    tex = '\\documentclass[preview]{standalone}'
    tex += '\\usepackage[hmargin = 0cm, vmargin = 0cm]{geometry}'
    tex += '\\usepackage{tikz}'
    tex += '\\usepackage{pgfplots}'
    tex += '\\begin{document}'
    tex += '\\begin{figure}[h!tbp]'
    tex += '\\centering'
    tex += '\\begin{tikzpicture}'
    tex += '\\begin{axis}['
    #tex += 'scatter / classes = {a = {mark = square *, blue}},'
    tex += 'height = 15cm,'
    tex += 'domain=' + str(xleft) + ':' + str(xright) + ','
    tex += 'grid = major,'
    tex += 'grid style = {dashed, gray!50},'
    tex += 'axis lines = middle,'
    tex += 'inner axis line style = {= >},'
    tex += 'xlabel = {\\large $x$},'
    tex += 'ylabel = {\\large $y$},'
    tex += 'yticklabel style = {inner ysep = 0pt, anchor = south east},'
    tex += 'xticklabel style= {inner xsep = 0pt, anchor = north west},'
    tex += 'xtick = {'
    tex += str(xleft) + ',' + str(xleft + detalx) + ', ..., ' + str(xright) + '},'
    tex += 'ytick = {'
    tex += str(ybot) + ',' + str(ybot + detaly) + ', ..., ' + str(ytop) + '},'
    tex += 'ymin = ' + str(ybot - detaly) + ','
    tex += 'ymax = ' + str(ytop + detaly) + ','
    tex += 'xmin = ' + str(xleft - detalx) + ','
    tex += 'xmax = ' + str(xright + detalx) + ','
    tex += 'after end axis/.code = {\\path (axis cs: 0,0) node [anchor = north west, yshift = -0.075cm] {0};}]'
    if(len(arr_x) == 2):
        tex += 'after end axis/.code = {\\path (axis cs:'+ str(arr_x[0].evalf())  + ','+ str(arr_y[0]) + ') node [anchor = south west, yshift = 0.075cm, xshift = 0.075cm] {A};}]'
        tex += 'after end axis/.code = {\\path (axis cs:'+ str(arr_x[1].evalf())  + ','+ str(arr_y[1]) + ') node [anchor = south west, yshift = 0.075cm, xshift = 0.075cm] {B};}]'
    tex += '\\addplot[color = red, thick, samples = 201] {' + str(a) + '*x*x*x + ' + str(b) + '*x*x+' + str(c) + '*x+' + str(d) + '};'
    tex += '\\legend{$' + functionLatex + '$}'
    if(len(arr_x)==2):
        tex += '\\addplot[scatter, only marks,scatter src = explicit symbolic]'
        tex += 'coordinates {(' + str(arr_x[0].evalf()) + ',' + str(arr_y[0]) + ')[a](' + str(arr_x[1].evalf()) + ',' + str(arr_y[1]) + ')[a]};'
    tex += '\\end{axis}'
    tex += '\\end{tikzpicture}'
    tex += '\\end{figure}'
    tex += '\\end{document}'
    #rint tex
    return tex2base64(tex)