Python matplotlib.pyplot 模块,tricontourf() 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用matplotlib.pyplot.tricontourf()

项目:nanopores    作者:mitschabaude    | 项目源码 | 文件源码
def fem2contour(u):
    mesh = u.function_space().mesh()
    v2d = dolfin.vertex_to_dof_map(u.function_space())

    # extract x and y coordinates of nodes
    x = mesh.coordinates()[:,0]
    y = mesh.coordinates()[:,1]
    triangles = mesh.cells()

    # Create triangulation.
    triang = mtri.Triangulation(x, y, triangles)

    # create array of node values from function
    z = u.vector()[v2d]

    # Plot the triangulation.
    plt.figure()
    plt.tricontourf(triang, z)
    #plt.triplot(triang, 'k-')
    #plt.title('Triangular grid')
项目:PyBGMM    作者:junlulocky    | 项目源码 | 文件源码
def draw_pdf_contours(dist, nlevels=200, subdiv=8, **kwargs):

    import math

    refiner = tri.UniformTriRefiner(triangle)
    trimesh = refiner.refine_triangulation(subdiv=subdiv)
    pvals = [dist.pdf(xy2bc(xy)) for xy in zip(trimesh.x, trimesh.y)]

    plt.tricontourf(trimesh, pvals, nlevels, **kwargs)
    plt.axis('equal')
    plt.xlim(0, 1)
    plt.ylim(0, 0.75**0.5)
    plt.axis('off')

    ## save plot
    # save_path = os.path.dirname(__file__) + '/gmplots'
    # if value:
    #     plt.savefig(save_path + "/dirichlet_" + str(value) + ".pdf")
    #     plt.savefig(save_path + "/dirichlet_" + str(value) + ".png")
    plt.show()
项目:BERNAISE    作者:gautelinga    | 项目源码 | 文件源码
def plot_contour(nodes, elems, vals,
                 title=None, clabel=None,
                 save=None, show=True):
    """ Contour plot; values given at nodes. """
    fig = Figure(title=title, clabel=clabel, save=save, show=show)
    plt.tricontourf(nodes[:, 0], nodes[:, 1], elems, vals)
    return fig
项目:BERNAISE    作者:gautelinga    | 项目源码 | 文件源码
def plot_quiver(nodes, elems, vals, title=None, clabel=None,
                save=None, show=True):
    """ Plots quivers with contour in the background.
    Values given at nodes. """
    fig = Figure(title=title, subplots=True, clabel=clabel,
                 save=save, show=show)

    vals_norm = np.sqrt(vals[:, 0]**2 + vals[:, 1]**2) + 1e-10
    # vals_norm_max = np.max(vals_norm)
    fig.colorbar_ax = fig.ax.tricontourf(nodes[:, 0], nodes[:, 1], elems,
                                         vals_norm)
    fig.ax.quiver(nodes[:, 0], nodes[:, 1],
                  vals[:, 0]/vals_norm, vals[:, 1]/vals_norm)
项目:BERNAISE    作者:gautelinga    | 项目源码 | 文件源码
def plot_fancy(nodes, elems, phi, charge, u=None, charge_max=None,
               show=False, save=None):
    """ Plots fancily. """
    fig = Figure(colorbar=False, tight_layout=True, show=show,
                 xlabel="", ylabel="", save=save, ticks=False)

    if charge_max is None:
        charge_max = max(np.max(np.abs(charge)), 1e-10)

    cmap = plt.cm.get_cmap('Greys')
    cmap._init()
    cmap._lut[:, :] = 0.
    length = len(cmap._lut[:, -1])
    # cmap._lut[:, -1] = np.linspace(0., 1.0, length)
    cmap._lut[:length/2, -1] = 0.
    cmap._lut[length/2:, -1] = 1.

    phi[phi > 1.] = 1.
    phi[phi < -1.] = -1.

    plt.tripcolor(nodes[:, 0], nodes[:, 1], elems, charge,
                  cmap=plt.get_cmap("coolwarm"), shading="gouraud",
                  vmin=-charge_max, vmax=charge_max)
    plt.tricontourf(nodes[:, 0], nodes[:, 1], elems, phi,
                    cmap=cmap, levels=[-2.0, 0., 2.0], antialiased=True)

    if u is not None:
        u_norm = np.sqrt(u[:, 0]**2 + u[:, 1]**2) + 1e-10
        colors = phi
        norm = plt.Normalize()
        norm.autoscale(colors)
        colormap = cmap  # plt.cm.get_cmap('inferno')
        cmap._lut[:, -1] = 0.5
        cmap._lut[length/2:, :-1] = 1.

        fig.ax.quiver(nodes[:, 0], nodes[:, 1],
                      u[:, 0]/u_norm, u[:, 1]/u_norm,
                      color=colormap(norm(colors)))

    return fig