Ejemplo n.º 1
0
def plot_1func_domain(plot_lst):
    inf_lst = extract_information(plot_lst)
    fig = plt.figure(figsize=(25, 2))
    ax = SubplotZero(fig, 111)
    fig.add_subplot(ax)
    for i in inf_lst:
        bound_color = i[0]
        print i
        xy_x = i[1][0][0][0]
        xy_y = i[1][0][0][1]
        lgt = i[1][0][1]
        rect = plt.Rectangle((xy_x, xy_y),
                             lgt,
                             0.5,
                             fill=True,
                             facecolor=bound_color,
                             edgecolor=bound_color,
                             linewidth=0)
        ax.add_patch(rect)
    plt.ylim((-0.25, 0.25))
    plt.xlim((-2150, 2150))
    plt.yticks([])
    # plt.savefig("graph2/" + fun_name + ".pdf", format="pdf")
    plt.savefig("papergraph/" + "erfbdvals.eps", format="eps")
    # plt.close()
    plt.show()
Ejemplo n.º 2
0
def plot_2vfunc_domain(plot_lst):
    inf_lst = extract_information2v(plot_lst)
    fig = plt.figure(figsize=(10, 10))
    ax = SubplotZero(fig, 111)
    fig.add_subplot(ax)
    # fun_name = inf_lst[1]
    for i in inf_lst:
        bound_color = i[0]
        # print i
        xy_x = i[1][0][0][0]
        xy_y = i[1][0][0][1]
        lgt = i[1][0][1]
        hgt = i[1][0][2]
        rect = plt.Rectangle((xy_x, xy_y),
                             lgt,
                             hgt,
                             fill=True,
                             facecolor=bound_color,
                             edgecolor='red',
                             linewidth=0)
        ax.add_patch(rect)
    # plt.ylim((-0.25, 0.25))
    plt.xlim((-2150, 2150))
    plt.ylim((-2150, 2150))
    plt.show()
Ejemplo n.º 3
0
def ellipse():

    # theta ranges from 0 to 2pi
    npts = 360
    theta = np.linspace(0, 2 * np.pi, npts)

    # well go through a range of eccentricities (forwards and backwards)
    n_ecc = 200
    e_tmp = np.linspace(0, 0.95, n_ecc)

    ecc = np.zeros(2 * n_ecc)
    ecc[0:n_ecc] = e_tmp[:]
    ecc[n_ecc:] = e_tmp[::-1]

    a = 1.0

    for n, e in enumerate(ecc):

        r = a * (1.0 - e**2) / (1.0 + e * np.cos(theta))

        x = r * np.cos(theta)
        y = r * np.sin(theta)

        # plotting
        fig = plt.figure(1)
        fig.clear()

        ax = SubplotZero(fig, 111)
        fig.add_subplot(ax)

        ax.set_aspect("equal", "datalim")

        ax.plot(x, y, color="k", linewidth=2)

        # second foci
        ax.scatter([-2.0 * a * e], [0], color="C0", marker="x", s=100)

        # primary foci
        ax.scatter([0], [0], color="C1", marker="x", s=100)

        ax.set_xlim(-2.5, 1.5)
        ax.set_ylim(-2., 2.)

        ax.text(-2.0, -1.5, "a = %5.3f, e = %6.4f" % (a, e))

        for direction in ["xzero", "yzero"]:
            # adds arrows at the ends of each axis
            ax.axis[direction].set_axisline_style("-|>")

            # adds X and Y-axis from the origin
            ax.axis[direction].set_visible(True)

        for direction in ["left", "right", "bottom", "top"]:
            # hides borders
            ax.axis[direction].set_visible(False)

        fig.set_size_inches(7.2, 7.2)

        plt.savefig("ellipse_{:03d}.png".format(n))
Ejemplo n.º 4
0
def rectangle(a, b, n):
    if 1:
        f = plt.figure(1)
        ax = SubplotZero(f, 111)
        f.add_subplot(ax)
        dx = (b - a) / float(n)
        total = 0
        for k in range(0, n):
            total = total + func((a + (k * dx)))
        return dx * total
Ejemplo n.º 5
0
def myplot(P):
    plt.xkcd()
    fig = plt.figure()
    ax = SubplotZero(fig, 111)
    fig.add_subplot(ax)
    plt.axhline(y=0, color='#636363')
    plt.axvline(x=0, color='#636363')
    ax.set(xlabel='$x$', ylabel='$f(x)$', title='Newton Method')
    x = arange(P - 2 * abs(P), P + 2 * abs(P), 0.01)
    y = [f(i) for i in x]
    ax.plot(x, y, label='$f(x)$')
    ax.plot([P], [0], 'ro-', label='root')
    ax.legend()
    plt.show()
Ejemplo n.º 6
0
 def plot_func(section, func):
     fig = plt.figure(1, (10, 6))
     ax = SubplotZero(fig, 1, 1, 1)
     fig.add_subplot(ax)
     x0 = linspace(section[0], section[1], 1000)
     y0 = []
     for i in range(1000):
         y0.append(func(x0[i]))
     ax.axis["xzero"].set_visible(True)
     ax.axis["xzero"].label.set_color('green')
     ax.axis["yzero"].set_visible(True)
     ax.axis["yzero"].label.set_color('green')
     plt.plot(x0, y0, 'r-', color='b')
     plt.show()
Ejemplo n.º 7
0
def test_SubplotZero():
    fig = plt.figure()

    ax = SubplotZero(fig, 1, 1, 1)
    fig.add_subplot(ax)

    ax.axis["xzero"].set_visible(True)
    ax.axis["xzero"].label.set_text("Axis Zero")

    for n in ["top", "right"]:
        ax.axis[n].set_visible(False)

    xx = np.arange(0, 2 * np.pi, 0.01)
    ax.plot(xx, np.sin(xx))
    ax.set_ylabel("Test")
Ejemplo n.º 8
0
 def creator(self, a, b, c, minn, maxx):
     '''A method that creates the graph and adjust the axis.'''
     y = list()
     x = np.linspace(minn, maxx)
     for i in x:
         y.append((a * i * i) + (b * i) + c)
     fig = plt.figure()
     ax = SubplotZero(fig, 111)
     fig.add_subplot(ax)
     ax.axis['xzero'].set_visible(True)
     ax.axis['yzero'].set_visible(True)
     for i in ["left", "right", "bottom", "top"]:
         ax.axis[i].set_visible(False)
     plt.plot(x, y)
     plt.show()
Ejemplo n.º 9
0
 def plot_func_str(section, expression):
     fig = plt.figure(1, (10, 6))
     ax = SubplotZero(fig, 1, 1, 1)
     fig.add_subplot(ax)
     x0 = linspace(section[0], section[1], 1000)
     x = symbols('x')
     y0 = []
     for i in range(1000):
         y0.append(sympify(expression).evalf(subs={x: x0[i]}))
     ax.axis["xzero"].set_visible(True)
     ax.axis["xzero"].label.set_color('green')
     ax.axis["yzero"].set_visible(True)
     ax.axis["yzero"].label.set_color('green')
     plt.plot(x0, y0, 'r-', color='b')
     plt.show()
Ejemplo n.º 10
0
def dyhotomia(request):
    if 1:
        postSave = float(request.POST['formA'])
        postS(postSave)
        l = 0.0
        lmax = 0.6
        E = 1e-4
        y = 0.0
        f = plt.figure(1)
        ax = SubplotZero(f, 111)
        f.add_subplot(ax)
        x = l
        xmax = lmax
        Ua = 0.0
        U = 0.0
        while (np.abs(l - lmax) >= E):
            Ua = func(l)
            U = func((l + lmax) / 2)
            if Ua * U > 0:
                l = (l + lmax) / 2
            else:
                lmax = (l + lmax) / 2
            y = (l + lmax) / 2

        for direction in ["xzero", "yzero"]:
            # adds arrows at the ends of each axis
            ax.axis[direction].set_axisline_style("-|>")

            # adds X and Y-axis from the origin
            ax.axis[direction].set_visible(True)

        for direction in ["left", "right", "bottom", "top"]:
            # hides borders
            ax.axis[direction].set_visible(False)
        x = np.linspace(x, xmax, 100)
        ax.plot(y, funcg(y), 'o', x, funcg(x))
        print(y)
        print(Ua)
        print(U)
        print(I)
        print(a)

    buf = io.BytesIO()
    plt.grid(True)
    plt.savefig(buf, format='svg')
    plt.close(f)
    response = HttpResponse(buf.getvalue(), content_type='image/svg+xml')
    return response
Ejemplo n.º 11
0
def myplot(P):
    plt.xkcd()
    fig = plt.figure()
    ax = SubplotZero(fig, 111)
    fig.add_subplot(ax)
    plt.axhline(y=0, color='#636363')
    plt.axvline(x=0, color='#636363')
    ax.set(xlabel='$x$', ylabel='$g(x)$', title='Fixed-Point Method')
    x = arange(P - 2 * abs(P), P + 2 * abs(P), 0.01)
    yg = [g(i) for i in x]
    yx = x
    ax.plot(x, yg, label='$g(x)$')
    ax.plot(x, yx, label='$x$')
    ax.plot([P], [g(P)], 'ro-', label='root')
    ax.legend()
    plt.show()
Ejemplo n.º 12
0
def test_SubplotZero():
    # Remove this line when this test image is regenerated.
    plt.rcParams['text.kerning_factor'] = 6

    fig = plt.figure()

    ax = SubplotZero(fig, 1, 1, 1)
    fig.add_subplot(ax)

    ax.axis["xzero"].set_visible(True)
    ax.axis["xzero"].label.set_text("Axis Zero")

    for n in ["top", "right"]:
        ax.axis[n].set_visible(False)

    xx = np.arange(0, 2 * np.pi, 0.01)
    ax.plot(xx, np.sin(xx))
    ax.set_ylabel("Test")
Ejemplo n.º 13
0
def dyhotomia(request):
    if 1:
        a = float(request.POST['a'])
        b = float(request.POST['b'])
        e = float(request.POST['e'])
        y=0.0
        i=a
        f = plt.figure(1)
        ax = SubplotZero(f, 111)
        f.add_subplot(ax)
        mas = np.arange(a, b, e)
        x = a
        xmax = b

        while(np.abs(a - b)>=e):
            Ua = func(a)
            U = func((a+b)/2)
            if Ua*U > 0:
                a = (a+b)/2
            else:
                b = (a+b)/2
            y = (a+b)/2

        for direction in ["xzero", "yzero"]:
            # adds arrows at the ends of each axis
            ax.axis[direction].set_axisline_style("-|>")

            # adds X and Y-axis from the origin
            ax.axis[direction].set_visible(True)

        for direction in ["left", "right", "bottom", "top"]:
            # hides borders
            ax.axis[direction].set_visible(False)
        x = np.linspace(x, xmax, 100)
        ax.plot(y, func(y), 'o', x, func(x))
        print(y)

    buf = io.BytesIO()
    plt.grid(True)
    plt.savefig(buf, format='svg')
    plt.close(f)
    response = HttpResponse(buf.getvalue(), content_type='image/svg+xml')
    return response
Ejemplo n.º 14
0
 def plot_point(self, point):
     x_limit = 10
     y_limit = 5
     fig = plt.figure(1, figsize=(8, 4))
     ax = SubplotZero(fig, 1, 1, 1)
     fig.add_subplot(ax)
     ax.grid(color='#eeeeee', linestyle='-', linewidth=2)
     ax.set_xticks(np.arange(-1 * x_limit, x_limit, 1))
     ax.set_xlim(-1 * x_limit, x_limit)
     ax.set_yticks(np.arange(-1 * y_limit, y_limit, 1))
     ax.set_ylim(-1 * y_limit, y_limit)
     ax.axis['xzero'].set_axisline_style('-|>')
     ax.axis['xzero'].set_visible(True)
     ax.axis["xzero"].label.set_text('$x_1$')
     ax.axis['yzero'].set_axisline_style('-|>')
     ax.axis['yzero'].set_visible(True)
     ax.axis["yzero"].label.set_text('$x_2$')
     ax.plot(*point, 'ro', label='$x^{*}$')
     ax.legend()
Ejemplo n.º 15
0
def mplimage(request):
    if 1:
        postSave = float(request.POST['formA'])
        postS(postSave)
        l = 0
        lmax = 0.6
        E = 1e-4
        y = 0.0
        iu = 0
        f = plt.figure(1)
        ax = SubplotZero(f, 111)
        f.add_subplot(ax)
        mas = np.arange(l, lmax, E)
        for i in mas:
            y1 = func(i)
            y2 = func(i + E)
            if y1 * y2 < 0:
                iu = (i + i + E) / 2
                break

        for direction in ["xzero", "yzero"]:
            # adds arrows at the ends of each axis
            ax.axis[direction].set_axisline_style("-|>")

            # adds X and Y-axis from the origin
            ax.axis[direction].set_visible(True)

        for direction in ["left", "right", "bottom", "top"]:
            # hides borders
            ax.axis[direction].set_visible(False)
        x = np.linspace(l, lmax, 100)
        ax.plot(iu, funcg(iu), 'o', x, funcg(x))
        print(iu)
        print(y1)
        print(y2)
        print(I)
    buf = io.BytesIO()
    plt.grid(True)
    plt.savefig(buf, format='svg')
    plt.close(f)
    response = HttpResponse(buf.getvalue(), content_type='image/svg+xml')
    return response
Ejemplo n.º 16
0
def newton(request):
    if 1:
        a = float(request.POST['a'])
        b = float(request.POST['b'])
        e = float(request.POST['e'])
        y=0.0
        i=a
        f = plt.figure(1)
        ax = SubplotZero(f, 111)
        f.add_subplot(ax)
        x = a
        xmax = b
        if(func(a)*d2Func(a) > 0):
            x0 = a
        else: x0 = b
        xn = x0 - func(x0) / dFunc(x0)
        while(np.abs(x0 - xn) > e):
            x0 = xn
            xn = x0 - func(x0) / dFunc(x0)

        for direction in ["xzero", "yzero"]:
            # adds arrows at the ends of each axis
            ax.axis[direction].set_axisline_style("-|>")

            # adds X and Y-axis from the origin
            ax.axis[direction].set_visible(True)

        for direction in ["left", "right", "bottom", "top"]:
            # hides borders
            ax.axis[direction].set_visible(False)
        x = np.linspace(x, xmax, 100)
        ax.plot(xn, func(xn), 'o', x, func(x))
        print(xn)

    buf = io.BytesIO()
    plt.grid(True)
    plt.savefig(buf, format='svg')
    plt.close(f)
    response = HttpResponse(buf.getvalue(), content_type='image/svg+xml')
    return response
# Create your views here.
Ejemplo n.º 17
0
def newton(request):
    if 1:
        postSave = float(request.POST['formA'])
        postS(postSave)
        l = 0.0
        lmax = 0.6
        E = 1e-4
        f = plt.figure(1)
        ax = SubplotZero(f, 111)
        f.add_subplot(ax)
        x = l
        xmax = lmax
        if (func(l) * d2Func(l) > 0):
            x0 = l
        else:
            x0 = lmax
        xn = x0 - func(x0) / dFunc(x0)
        while (np.abs(x0 - xn) > E):
            x0 = xn
            xn = x0 - func(x0) / dFunc(x0)

        for direction in ["xzero", "yzero"]:
            # adds arrows at the ends of each axis
            ax.axis[direction].set_axisline_style("-|>")

            # adds X and Y-axis from the origin
            ax.axis[direction].set_visible(True)

        for direction in ["left", "right", "bottom", "top"]:
            # hides borders
            ax.axis[direction].set_visible(False)
        x = np.linspace(x, xmax, 100)
        ax.plot(xn, funcg(xn), 'o', x, funcg(x))
        print("newton", xn)

    buf = io.BytesIO()
    plt.grid(True)
    plt.savefig(buf, format='svg')
    plt.close(f)
    response = HttpResponse(buf.getvalue(), content_type='image/svg+xml')
    return response
Ejemplo n.º 18
0
def main():
    # データ
    x = np.arange(-5, 5, 1)
    y = [1.0] * 1000

    # プロット
    fig = plt.figure()
    ax = SubplotZero(fig, 111)
    fig.add_subplot(ax)
    plot_arrow(ax, x, y, 1)

    # 表示設定
    margin = 0.5
    set_display(fig, ax)
    ax.set_xlim(x[0] - margin, x[-1] + margin)
    ax.set_ylim(-0.2, 1.5)

    # ファイル保存
    fig.savefig("arrow.png")

    # 表示
    plt.show()
Ejemplo n.º 19
0
    def nice():
        x, y, z = symbols('x y z')
        init_printing(use_unicode=True)
        rango_1 = float(input("rango 1: "))
        rango_2 = float(input("rango 2: "))
        resolution = int(input("resolucion: "))
        print("formula")
        function = input()

        results=[]
        value_x = []
        value_y = []
        cosa = ((rango_2 - rango_1) / resolution)


        for x_n in np.arange(rango_1,rango_2, cosa):
            cosa2 = (rango_1 + (((rango_2 - rango_1) / 2 * resolution) * (2*x_n - 1)))
            value_y.append(cosa * sympify(function).evalf(subs={x: cosa2}))
            #value_y.append(sympify("x**2").evalf(subs={x: x_n}))

        for y_n in np.arange(rango_1,rango_2, cosa):
            value_x.append(y_n)

        print(value_x,value_y)

        fig = plt.figure()
        ax = SubplotZero(fig,111)
        fig.add_subplot(ax)

        for direction in ["xzero","yzero"]:
            ax.axis[direction].set_axisline_style("-|>")
            ax.axis[direction].set_visible(True)

        for direction in ["left","right","bottom","top"]:
            ax.axis[direction].set_visible(False)

        ax.y(value_x, value_y)
        plt.savefig('foo.svg')
Ejemplo n.º 20
0
    def calulitos(a_o, b_o, n_o, function):
        s_x = symbols("x")
        print("funcion a usar ---> ", function)

        np.seterr(divide='ignore', invalid='ignore')

        f = lambda x: lambdify(s_x, sympify(function), 'numpy')(x)

        a = a_o
        b = b_o
        N = n_o
        n = n_o  # Use n*N+1 points to plot the function smoothly

        xe = np.linspace(a, b, N + 1)
        y = f(xe)
        X = np.linspace(a, b, n * N + 1)
        Y = f(X)
        fig = plt.figure()
        ax = SubplotZero(fig, 111)
        fig.add_subplot(ax)

        for direction in ["xzero", "yzero"]:
            ax.axis[direction].set_axisline_style("-|>")
            ax.axis[direction].set_visible(True)

        for direction in ["left", "right", "bottom", "top"]:
            ax.axis[direction].set_visible(False)

        plt.subplot(1, 3, 2)
        plt.plot(X, Y, color="red")
        x_mid = (xe[:-1] + xe[1:]) / 2  # Midpoints
        y_mid = f(x_mid)
        plt.plot(x_mid, y_mid, color="red")
        plt.bar(x_mid, y_mid, width=(b - a) / N, edgecolor='b')
        plt.title('Midpoint Riemann Sum, N = {}'.format(N))

        plt.savefig('foo.png', dpi=500)
        vistas.resultado("foo.png")
Ejemplo n.º 21
0
def mplimage(request):
    if 1:
        a = float(request.POST['a'])
        b = float(request.POST['b'])
        e = float(request.POST['e'])
        y=0.0
        i=a
        f = plt.figure(1)
        ax = SubplotZero(f, 111)
        f.add_subplot(ax)
        mas = np.arange(a, b, e)

        for i in mas:
            y1=func(i)
            y2=func(i+e)
            if y1*y2<0:
                y = (i + i+e)/2

        for direction in ["xzero", "yzero"]:
            # adds arrows at the ends of each axis
            ax.axis[direction].set_axisline_style("-|>")

            # adds X and Y-axis from the origin
            ax.axis[direction].set_visible(True)

        for direction in ["left", "right", "bottom", "top"]:
            # hides borders
            ax.axis[direction].set_visible(False)
        x = np.linspace(a, b, 100)
        ax.plot(y, func(y), 'o', x, func(x))
        print(y)
    buf = io.BytesIO()
    plt.grid(True)
    plt.savefig(buf, format='svg')
    plt.close(f)
    response = HttpResponse(buf.getvalue(), content_type='image/svg+xml')
    return response
Ejemplo n.º 22
0
def drawGraph(g, layoutG=None, **kwargs):
    if not layoutG:
        layoutG = g

    edges = g.edges.data()
    tails = [e[0:2] for e in edges if ('wedge' in e[2])]
    tailGraph = g.edge_subgraph(tails)

    heads = [e[0:2] for e in edges if ('wedge' not in e[2])]
    headGraph = g.edge_subgraph(heads)

    defaultOpt = {
        'pos': nx.drawing.nx_agraph.graphviz_layout(layoutG, prog='dot'),
        'node_size': 2000,
        'arrowstyle': '->',
        'font': 'dejavu sans'
    }
    sharedOpt = {**defaultOpt, **kwargs}

    nodeOpt = {
        **sharedOpt,
        'node_color': 'white',
        'node_shape': "o",
        # 'font_family': 'dejavu sans'
    }

    arrowOpt = {
        **sharedOpt, 'node_shape': "s",
        'width': 2,
        'edge_color': '#AAAAAA',
        'arrowsize': 30
    }

    arrowHeadOpt = {**arrowOpt}

    arrowTailOpt = {**arrowOpt, 'arrowstyle': 'wedge'}

    with plt.xkcd():
        fig, ax = plt.subplots(1)
        fig.patch.set_alpha(0)

        ax.axis('off')

        ax = SubplotZero(fig, 111)
        fig.add_subplot(ax)
        plt.xticks([])
        plt.yticks([])

        ax.set_ylabel('go up')
        ax.set_xlabel('go right')

        for s in ['right', 'top']:
            ax.axis[s].set_visible(False)

        for s in ['bottom', 'left']:
            ax.axis[s].set_axisline_style("->")

        ax.patch.set_alpha(0)

        nx.drawing.draw_networkx_nodes(g, **nodeOpt)
        nx.drawing.draw_networkx_labels(g, **nodeOpt)

        drawEdgesAndLabels(arrowHeadOpt, headGraph)
        drawEdgesAndLabels(arrowTailOpt, tailGraph)
Ejemplo n.º 23
0
    def plot_(self,
              model_list,
              rec_prec_list,
              show_full_line=True,
              show_dotted_line=True,
              self_adaption=False,
              show_legend=True):
        # 清图
        plt.clf()
        # ax = self.figure.add_axes([0.1, 0.1, 0.8, 0.8])
        #https://blog.csdn.net/wuzlun/article/details/80053277

        if not self_adaption:
            fig = self.figure
            ax = SubplotZero(fig, 1, 1, 1)
            fig.add_subplot(ax)
            ax.set_ylim(-0.01, 1.01)
            # ax.set_yticks([-1,-0.5,0,0.5,1])
            ax.set_xlim([-0.01, 1.01])

            # fig = plt.figure(1, (10, 10))
            # ax = SubplotZero(fig, 1, 1, 1)
            # fig.add_subplot(ax)
            # ax.set_ylim(-0.01,1.01)
            # # ax.set_yticks([-1,-0.5,0,0.5,1])
            # ax.set_xlim([-0.01,1.01])
        else:
            ax = self.figure.add_axes([0.1, 0.1, 0.8, 0.8])
        # ax = self.figure.add_axes([0.1, 0.1, 0.8, 0.8])

        if len(model_list) < 1 or len(rec_prec_list) < 1:
            self.canvas.draw()
            return

        if show_full_line and show_dotted_line:
            for i in range(len(model_list)):
                color = np.random.rand(3, )
                ax.plot(rec_prec_list[4 * i],
                        rec_prec_list[4 * i + 1],
                        c=color,
                        ls=":")  # rec, prec
                ax.plot(rec_prec_list[4 * i + 2],
                        rec_prec_list[4 * i + 3],
                        label=model_list[i],
                        c=color)  # mrec, mprec
        elif show_full_line:
            for i in range(len(model_list)):
                color = np.random.rand(3, )
                ax.plot(rec_prec_list[4 * i + 2],
                        rec_prec_list[4 * i + 3],
                        label=model_list[i],
                        c=color)  # mrec, mprec
        elif show_dotted_line:
            for i in range(len(model_list)):
                color = np.random.rand(3, )
                ax.plot(rec_prec_list[4 * i],
                        rec_prec_list[4 * i + 1],
                        c=color,
                        label=model_list[i],
                        ls=":")  # rec, prec
        else:
            self.canvas.draw()
            return

        ax.set_xlabel('recall')
        ax.set_ylabel('precision')
        ax.set_title('P-R curve')
        if show_legend:
            ax.legend()
        # ax.legend(loc='lower left')
        self.canvas.draw()
Ejemplo n.º 24
0
"""
================
Axis line styles
================

This example shows some configurations for axis style.
"""

from mpl_toolkits.axisartist.axislines import SubplotZero
import matplotlib.pyplot as plt
import numpy as np

if 1:
    fig = plt.figure()
    ax = SubplotZero(fig, 111)
    fig.add_subplot(ax)

    for direction in ["xzero", "yzero"]:
        # adds arrows at the ends of each axis
        ax.axis[direction].set_axisline_style("-|>")

        # adds X and Y-axis from the origin
        ax.axis[direction].set_visible(True)

    for direction in ["left", "right", "bottom", "top"]:
        # hides borders
        ax.axis[direction].set_visible(False)

    x = np.linspace(-0.5, 1., 100)
    ax.plot(x, np.sin(x * np.pi))
Ejemplo n.º 25
0
# -*- coding: utf-8 -*-
"""
Created on Mon May 11 20:25:31 2020

@author: edels
"""

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.axisartist.axislines import SubplotZero

t = np.linspace(0, 2 * np.pi, 15)
V = np.sin(t)

fig = plt.figure(figsize=(1, 1))
ax = SubplotZero(fig, 1, 1, 1)
fig.add_subplot(ax)
ax.axis["xzero"].set_visible(True)

for n in ["bottom", "top", "right"]:
    ax.axis[n].set_visible(False)

# Step graph
ax.step(t, V, color="black", linewidth=2)

# Stem graph
#(markerline, stemlines, baselines) = ax.stem(t, V, linefmt = "black", basefmt = " ", use_line_collection = True)
#plt.setp(markerline, color = "black", markersize = 3) # Allow to edit stem markerline color

# Continuous line graph
#ax.plot(t, V, color = "black", linewidth = 2)
Ejemplo n.º 26
0
                    alphabet[4],
                    horizontalalignment='center',
                    verticalalignment='center',
                    fontsize=16,
                    fontweight='demibold',
                    transform=ax.transAxes)

        plotting.remove_axis_junk(ax)
        t = np.arange(p_net.shape[1]) * PSET.dt * PSET.decimate_q
        inds = (t >= T[0]) & (t <= T[1])
        ax.plot(t[inds], p_net[i, inds], 'k', lw=1)
        ax.set_ylabel(ylabel)
        ax.set_xticklabels([])

    # panel F. Illustration of 4-sphere volume conductor model geometry
    ax = SubplotZero(fig, gs[2, 1])
    fig.add_subplot(ax)
    ax.set_title('four-sphere volume conductor model')

    for direction in ["xzero"]:
        ax.axis[direction].set_visible(True)

    for direction in ["left", "right", "bottom", "top"]:
        ax.axis[direction].set_visible(False)

    theta = np.linspace(0, np.pi, 31)

    # draw some circles:
    for i, r, label in zip(range(4), PSET.foursphereParams['radii'],
                           ['brain', 'CSF', 'skull', 'scalp']):
        ax.plot(np.cos(theta) * r,
Ejemplo n.º 27
0
def ellipse():

    # theta ranges from 0 to 2pi
    npts = 360
    theta = np.linspace(0, 2 * np.pi, npts)

    e = 0.5
    a = 1.0

    r = a * (1.0 - e**3) / (1.0 + e * np.cos(theta))

    x = r * np.cos(theta)
    y = r * np.sin(theta)

    # plotting
    for n in range(npts):

        fig = plt.figure(1)
        fig.clear()

        ax = SubplotZero(fig, 111)
        fig.add_subplot(ax)

        ax.set_aspect("equal", "datalim")

        ax = plt.gca()
        ax.set_aspect("equal", "datalim")

        # draw the ellipse
        ax.plot(x, y, color="k", linewidth=2)

        # draw our current point
        ax.scatter([x[n]], [y[n]], color="k", s=75)

        # second foci
        ax.scatter([-2.0 * a * e], [0], color="C0", marker="x", s=200)

        # primary foci
        ax.scatter([0], [0], color="C1", marker="x", s=200)

        # draw lines connecting the foci to the current point
        ax.plot([0, x[n]], [0, y[n]], color="C1", zorder=100, linewidth=2)
        ax.plot([-2.0 * a * e, x[n]], [0, y[n]],
                color="C0",
                zorder=100,
                linewidth=2)

        ax.set_xlim(-2.5, 1.5)
        ax.set_ylim(-2., 2.)

        len1 = np.sqrt((x[n] - 0)**2 + (y[n] - 0)**2)
        len2 = np.sqrt((x[n] - (-2.0 * a * e))**2 + (y[n] - 0)**2)

        ax.set_title("Ellipse, eccenticity = {:5.3f}".format(e))

        ax.text(-1.5, -1.25, "r length: {:5.3f}".format(len1), color="C1")
        ax.text(-1.5, -1.5, "r' length: {:5.3f}".format(len2), color="C0")
        ax.text(-1.5, -1.75, "r + r' = {:5.3f}".format(len1 + len2))

        for direction in ["xzero", "yzero"]:
            # adds arrows at the ends of each axis
            ax.axis[direction].set_axisline_style("-|>")

            # adds X and Y-axis from the origin
            ax.axis[direction].set_visible(True)

        for direction in ["left", "right", "bottom", "top"]:
            # hides borders
            ax.axis[direction].set_visible(False)

        fig.set_size_inches(7.2, 7.2)

        fig.set_size_inches(7.2, 7.2)

        plt.savefig("ellipsedraw_{:03d}.png".format(n))
Ejemplo n.º 28
0
def plot_polarized_light(intensities,
                         deltaPhase=0,
                         fig=None,
                         show_components=False):
    if fig is None:
        fig = plt.figure(figsize=(20, 10))

    X = np.linspace(0, 2 * np.pi)
    Y = np.zeros_like(X)
    Z = np.zeros_like(X)

    V = intensities[0] * np.sin(X)
    W = intensities[1] * np.sin(X - deltaPhase)
    U = np.zeros_like(W)
    ax = fig.add_subplot(121, projection='3d', azim=-25, elev=20)

    ax.quiver(X, Y, Z, U, V, W, arrow_length_ratio=0.05, label="E")

    if show_components:
        ax.quiver(X,
                  Y,
                  Z,
                  U,
                  V,
                  np.zeros_like(W),
                  color=(1, 0, 0, 1),
                  arrow_length_ratio=0.05,
                  label="Ex")
        ax.quiver(X,
                  Y,
                  Z,
                  U,
                  np.zeros_like(V),
                  W,
                  color=(0, 1, 0, 1),
                  arrow_length_ratio=0.05,
                  label="Ey")

    ax.legend()

    X_ax = np.array([-(1), 0, 0])
    Y_ax = np.array([0, 1, 0])
    Z_ax = np.array([0, 0, -1])
    U_ax = np.array([5 + 2 * np.pi, 0, 0])
    V_ax = np.array([0, -1.5, 0])
    W_ax = np.array([0, 0, 1.5])
    ax.quiver(X_ax,
              Y_ax,
              Z_ax,
              U_ax,
              V_ax,
              W_ax,
              arrow_length_ratio=0.01,
              color=(0, 0, 0, 1))

    for x, y, z, txt in zip(X_ax + U_ax, Y_ax + V_ax, Z_ax + W_ax,
                            ["Z", "X", "Y"]):
        ax.text(x - 0.1, y, z, txt, fontsize=16)

    ax_2d = SubplotZero(fig, 122)
    fig.add_subplot(ax_2d)

    theta = np.linspace(0, 2 * np.pi, 1000)
    ax_2d.plot(np.cos(theta), np.sin(theta), 'k--', linewidth=2)

    # plt.annotate(s='Ey', xy=(0, -intensities[1]), xytext=(0, intensities[1]), horizontalalignment='center',
    #              verticalalignment='center',
    #              color='black', arrowprops=dict(arrowstyle='<->'),fontsize=18)
    #              verticalalignment='center',
    #              color='black', arrowprops=dict(arrowstyle='<->', shrinkA=0, shrinkB=0),
    ax_2d.plot(V, W, 'b-', linewidth=5)

    if intensities[0] > 1e-4:
        ax_2d.arrow(-0.8 * intensities[0],
                    0,
                    1.8 * intensities[0],
                    0,
                    linewidth=0,
                    width=0.01,
                    color='black',
                    shape="full",
                    length_includes_head=True)
        ax_2d.arrow(+0.8 * intensities[0],
                    0,
                    -1.8 * intensities[0],
                    0,
                    linewidth=0,
                    width=0.01,
                    color='black',
                    shape="full",
                    length_includes_head=True)
        plt.annotate(s='Ex',
                     xy=(-0.9 * intensities[0], 0.03),
                     xytext=(0.9 * intensities[0], 0.02),
                     horizontalalignment='center',
                     fontsize=18,
                     color='black')

    if intensities[1] > 1e-4:
        ax_2d.arrow(0,
                    -0.8 * intensities[1],
                    0,
                    1.8 * intensities[1],
                    linewidth=0,
                    width=0.01,
                    color='black',
                    shape="full",
                    length_includes_head=True)
        ax_2d.arrow(0,
                    +0.8 * intensities[1],
                    0,
                    -1.8 * intensities[1],
                    linewidth=0,
                    width=0.01,
                    color='black',
                    shape="full",
                    length_includes_head=True)
        plt.annotate(s='Ey',
                     xy=(0.06, -0.9 * intensities[1]),
                     xytext=(0.06, 0.9 * intensities[1]),
                     horizontalalignment='center',
                     fontsize=18,
                     color='black')
    # ax_2d.plot([0, 0],[0,intensities[1]],'k->', linewidth=4)

    ax_2d.set_xlim([-1.1, 1.1])
    ax_2d.set_ylim([-1.1, 1.1])
    # # ax_2d.text(1,0,"X", fontsize=16)
    # # ax_2d.text(0,1,"Y", fontsize=16)
    plt.xticks([])
    plt.yticks([])
    ax_2d.axis('off')
    # for direction in ["xzero", "yzero"]:
    #     ax_2d.axis[direction].set_axisline_style("-|>")
    #     ax_2d.axis[direction].set_visible(True)
    for direction in ["left", "right", "bottom", "top"]:
        ax_2d.axis[direction].set_visible(False)

    ax.set_axis_off()

    ax.set_xlim([0, 2 * np.pi])
    ax.set_ylim([-0.4, 0.4])
    ax.set_zlim([-0.4, 0.4])
    fig.tight_layout()
    plt.show()
Ejemplo n.º 29
0
def plot_enu(data1 = [],dataName1='',data2 = [],dataName2='',data3 = [],dataName3='',data12_scale_y=0,data3_scale_y=0):
# 第一个数据配置:
    data1_scale_y = data12_scale_y # y轴范围
    data1_epoch = len(data1) #x轴范围
    data1_yname = "errors/m"
    data1_xname = "epoch/s"
    data1_label = dataName1
# 第二个数据配置:
    data2_scale_y = data12_scale_y # y轴范围
    data2_epoch = len(data2) #x轴范围
    data2_yname = "errors/m"
    data2_xname = "epoch/s"
    data2_label = dataName2
# 第三个数据配置:
    data3_scale_y = data3_scale_y # y轴范围
    data3_epoch = len(data3) #x轴范围
    data3_yname = "errors/m"
    data3_xname = "epoch/s"
    data3_label = dataName3

# 只绘制一张图,含三个数据集----------------------------------------------------
#     data1x = np.linspace(0, data1_epoch, data1_epoch)
#     data2x = np.linspace(0, data2_epoch, data2_epoch)
#     data3x = np.linspace(0, data3_epoch, data3_epoch)
#     fig = plt.figure(1)
#     ax = SubplotZero(fig, 1, 1, 1)
#     ax.axhline(0, color='black', lw=1)
#     fig.add_subplot(ax)
#     fig.set_size_inches(8, 4)
#     fig.subplots_adjust(hspace=0.5)
#     plt.plot(data3x, data3, "g.", label=data3_label)
#     plt.plot(data2x, data2, "b.", label=data2_label)
#     plt.plot(data1x, data1, "r.", label=data1_label)
#     plt.grid("on")
#     plt.ylabel(data1_yname, fontproperties=myfont)
#     plt.xlabel(data1_xname, fontproperties=myfont)
#     plt.ylim(-data1_scale_y, data1_scale_y)
#     plt.legend()

# 绘制两张图----------------------------------------------------
# 第一张图,含两个数据集
    data1x = np.linspace(0, data1_epoch, data1_epoch)
    data2x = np.linspace(0, data2_epoch, data2_epoch)
    fig = plt.figure(1)
    ax = SubplotZero(fig, 2, 1, 1)
    ax.axhline(0, color='black', lw=1)
    fig.add_subplot(ax)
    fig.set_size_inches(8, 4)
    fig.subplots_adjust(hspace=0.5)
    plt.plot(data2x, data2, "b.", label=data2_label)
    plt.plot(data1x, data1, "r.", label=data1_label)
    plt.grid("on")
    plt.ylabel(data1_yname, fontproperties=myfont)
    plt.xlabel(data1_xname, fontproperties=myfont)
    plt.ylim(-data1_scale_y, data1_scale_y)
    plt.legend()
# 第二张图,含一个数据集
    data3x = np.linspace(0, data3_epoch, data3_epoch)
    fig = plt.figure(1)
    ax = SubplotZero(fig, 2, 1, 2)
    ax.axhline(0, color='black', lw=1)
    fig.add_subplot(ax)
    fig.set_size_inches(8, 4)
    fig.subplots_adjust(hspace=0.5)
    plt.plot(data3x, data3, "g.", label=data3_label)
    plt.grid("on")
    plt.ylabel(data3_yname, fontproperties=myfont)
    plt.xlabel(data3_xname, fontproperties=myfont)
    plt.ylim(-data3_scale_y, data3_scale_y)
    plt.legend()


    plt.show()
Ejemplo n.º 30
0
ax0.axis('off')
ax0.set_title('extracellular potential')
ax1 = fig.add_subplot(gs[:6, 1], aspect='equal')  # dipole moment ill.
ax1.axis('off')
ax1.set_title('extracellular potential')
ax2 = fig.add_subplot(gs[:6, 2], aspect='equal')  # dipole moment ill.
ax2.axis('off')
ax2.set_title('magnetic field')
# ax3 = fig.add_subplot(gs[0, 3], aspect='equal')             # spherical shell model ill.
# ax3.set_title('4-sphere volume conductor')
# ax4 = fig.add_subplot(gs[1, 3],
# aspect='equal'
# )                 # MEG/EEG forward model ill.
# ax4.set_title('EEG and MEG signal detection')

ax3 = SubplotZero(fig, gs[7:, 0])
fig.add_subplot(ax3)
ax3.set_title('4-sphere volume conductor', verticalalignment='bottom')
ax4 = fig.add_subplot(gs[7:, 1])  # EEG
ax4.set_title('scalp electric potential $\phi_\mathbf{p}(\mathbf{r})$')
ax5 = fig.add_subplot(gs[7:, 2], sharey=ax4)  # MEG
# ax5.set_title('scalp magnetic field')

#morphology - line sources for panels A and B
zips = []
xz = cell.get_idx_polygons()
for x, z in xz:
    zips.append(list(zip(x, z)))
for ax in [ax0]:
    polycol = PolyCollection(zips,
                             linewidths=(0.5),