Python matplotlib.pyplot.tripcolor() Examples

The following are code examples for showing how to use matplotlib.pyplot.tripcolor(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: ble5-nrf52-mac   Author: tomasero   File: test_triangulation.py    MIT License 6 votes vote down vote up
def test_tripcolor():
    x = np.asarray([0, 0.5, 1, 0,   0.5, 1,   0, 0.5, 1, 0.75])
    y = np.asarray([0, 0,   0, 0.5, 0.5, 0.5, 1, 1,   1, 0.75])
    triangles = np.asarray([
        [0, 1, 3], [1, 4, 3],
        [1, 2, 4], [2, 5, 4],
        [3, 4, 6], [4, 7, 6],
        [4, 5, 9], [7, 4, 9], [8, 7, 9], [5, 8, 9]])

    # Triangulation with same number of points and triangles.
    triang = mtri.Triangulation(x, y, triangles)

    Cpoints = x + 0.5*y

    xmid = x[triang.triangles].mean(axis=1)
    ymid = y[triang.triangles].mean(axis=1)
    Cfaces = 0.5*xmid + ymid

    plt.subplot(121)
    plt.tripcolor(triang, Cpoints, edgecolors='k')
    plt.title('point colors')

    plt.subplot(122)
    plt.tripcolor(triang, facecolors=Cfaces, edgecolors='k')
    plt.title('facecolors') 
Example 2
Project: neural-network-animation   Author: miloharper   File: test_triangulation.py    MIT License 6 votes vote down vote up
def test_tripcolor():
    x = np.asarray([0, 0.5, 1, 0,   0.5, 1,   0, 0.5, 1, 0.75])
    y = np.asarray([0, 0,   0, 0.5, 0.5, 0.5, 1, 1,   1, 0.75])
    triangles = np.asarray([
        [0, 1, 3], [1, 4, 3],
        [1, 2, 4], [2, 5, 4],
        [3, 4, 6], [4, 7, 6],
        [4, 5, 9], [7, 4, 9], [8, 7, 9], [5, 8, 9]])

    # Triangulation with same number of points and triangles.
    triang = mtri.Triangulation(x, y, triangles)

    Cpoints = x + 0.5*y

    xmid = x[triang.triangles].mean(axis=1)
    ymid = y[triang.triangles].mean(axis=1)
    Cfaces = 0.5*xmid + ymid

    plt.subplot(121)
    plt.tripcolor(triang, Cpoints, edgecolors='k')
    plt.title('point colors')

    plt.subplot(122)
    plt.tripcolor(triang, facecolors=Cfaces, edgecolors='k')
    plt.title('facecolors') 
Example 3
Project: python3_ios   Author: holzschu   File: test_triangulation.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_tripcolor():
    x = np.asarray([0, 0.5, 1, 0,   0.5, 1,   0, 0.5, 1, 0.75])
    y = np.asarray([0, 0,   0, 0.5, 0.5, 0.5, 1, 1,   1, 0.75])
    triangles = np.asarray([
        [0, 1, 3], [1, 4, 3],
        [1, 2, 4], [2, 5, 4],
        [3, 4, 6], [4, 7, 6],
        [4, 5, 9], [7, 4, 9], [8, 7, 9], [5, 8, 9]])

    # Triangulation with same number of points and triangles.
    triang = mtri.Triangulation(x, y, triangles)

    Cpoints = x + 0.5*y

    xmid = x[triang.triangles].mean(axis=1)
    ymid = y[triang.triangles].mean(axis=1)
    Cfaces = 0.5*xmid + ymid

    plt.subplot(121)
    plt.tripcolor(triang, Cpoints, edgecolors='k')
    plt.title('point colors')

    plt.subplot(122)
    plt.tripcolor(triang, facecolors=Cfaces, edgecolors='k')
    plt.title('facecolors') 
Example 4
Project: psychrometric-chart-makeover   Author: buds-lab   File: test_triangulation.py    MIT License 6 votes vote down vote up
def test_tripcolor():
    x = np.asarray([0, 0.5, 1, 0,   0.5, 1,   0, 0.5, 1, 0.75])
    y = np.asarray([0, 0,   0, 0.5, 0.5, 0.5, 1, 1,   1, 0.75])
    triangles = np.asarray([
        [0, 1, 3], [1, 4, 3],
        [1, 2, 4], [2, 5, 4],
        [3, 4, 6], [4, 7, 6],
        [4, 5, 9], [7, 4, 9], [8, 7, 9], [5, 8, 9]])

    # Triangulation with same number of points and triangles.
    triang = mtri.Triangulation(x, y, triangles)

    Cpoints = x + 0.5*y

    xmid = x[triang.triangles].mean(axis=1)
    ymid = y[triang.triangles].mean(axis=1)
    Cfaces = 0.5*xmid + ymid

    plt.subplot(121)
    plt.tripcolor(triang, Cpoints, edgecolors='k')
    plt.title('point colors')

    plt.subplot(122)
    plt.tripcolor(triang, facecolors=Cfaces, edgecolors='k')
    plt.title('facecolors') 
Example 5
Project: SignLanguage_ML   Author: mareep-raljodid   File: test_triangulation.py    MIT License 6 votes vote down vote up
def test_tripcolor():
    x = np.asarray([0, 0.5, 1, 0,   0.5, 1,   0, 0.5, 1, 0.75])
    y = np.asarray([0, 0,   0, 0.5, 0.5, 0.5, 1, 1,   1, 0.75])
    triangles = np.asarray([
        [0, 1, 3], [1, 4, 3],
        [1, 2, 4], [2, 5, 4],
        [3, 4, 6], [4, 7, 6],
        [4, 5, 9], [7, 4, 9], [8, 7, 9], [5, 8, 9]])

    # Triangulation with same number of points and triangles.
    triang = mtri.Triangulation(x, y, triangles)

    Cpoints = x + 0.5*y

    xmid = x[triang.triangles].mean(axis=1)
    ymid = y[triang.triangles].mean(axis=1)
    Cfaces = 0.5*xmid + ymid

    plt.subplot(121)
    plt.tripcolor(triang, Cpoints, edgecolors='k')
    plt.title('point colors')

    plt.subplot(122)
    plt.tripcolor(triang, facecolors=Cfaces, edgecolors='k')
    plt.title('facecolors') 
Example 6
Project: Blackjack-Tracker   Author: martinabeleda   File: test_triangulation.py    MIT License 6 votes vote down vote up
def test_tripcolor():
    x = np.asarray([0, 0.5, 1, 0,   0.5, 1,   0, 0.5, 1, 0.75])
    y = np.asarray([0, 0,   0, 0.5, 0.5, 0.5, 1, 1,   1, 0.75])
    triangles = np.asarray([
        [0, 1, 3], [1, 4, 3],
        [1, 2, 4], [2, 5, 4],
        [3, 4, 6], [4, 7, 6],
        [4, 5, 9], [7, 4, 9], [8, 7, 9], [5, 8, 9]])

    # Triangulation with same number of points and triangles.
    triang = mtri.Triangulation(x, y, triangles)

    Cpoints = x + 0.5*y

    xmid = x[triang.triangles].mean(axis=1)
    ymid = y[triang.triangles].mean(axis=1)
    Cfaces = 0.5*xmid + ymid

    plt.subplot(121)
    plt.tripcolor(triang, Cpoints, edgecolors='k')
    plt.title('point colors')

    plt.subplot(122)
    plt.tripcolor(triang, facecolors=Cfaces, edgecolors='k')
    plt.title('facecolors') 
Example 7
Project: pgmult   Author: HIPS   File: dirichlet.py    MIT License 6 votes vote down vote up
def test_pcolor_heatmap():
    # import matplotlib.tri as tri
    from matplotlib import pyplot as plt

    mesh3D = mesh(100,edges=True)
    mesh2D = proj_to_2D(mesh3D)
    # triangulation = tri.Triangulation(mesh2D) # this is called in tripcolor

    data = np.zeros((3,3))
    data[0,1] += 1

    vals = np.exp(log_dirichlet_density(mesh3D,2.,data=data.sum(0)))
    temp = log_censored_dirichlet_density(mesh3D,2.,data=data)
    censored_vals = np.exp(temp - temp.max())

    plt.figure()
    plt.tripcolor(mesh2D[:,0],mesh2D[:,1],vals)
    plt.title('uncensored')

    plt.figure()
    plt.tripcolor(mesh2D[:,0],mesh2D[:,1],censored_vals)
    plt.title('censored') 
Example 8
Project: lambda-tensorflow-object-detection   Author: mikylucky   File: test_triangulation.py    GNU General Public License v3.0 6 votes vote down vote up
def test_tripcolor():
    x = np.asarray([0, 0.5, 1, 0,   0.5, 1,   0, 0.5, 1, 0.75])
    y = np.asarray([0, 0,   0, 0.5, 0.5, 0.5, 1, 1,   1, 0.75])
    triangles = np.asarray([
        [0, 1, 3], [1, 4, 3],
        [1, 2, 4], [2, 5, 4],
        [3, 4, 6], [4, 7, 6],
        [4, 5, 9], [7, 4, 9], [8, 7, 9], [5, 8, 9]])

    # Triangulation with same number of points and triangles.
    triang = mtri.Triangulation(x, y, triangles)

    Cpoints = x + 0.5*y

    xmid = x[triang.triangles].mean(axis=1)
    ymid = y[triang.triangles].mean(axis=1)
    Cfaces = 0.5*xmid + ymid

    plt.subplot(121)
    plt.tripcolor(triang, Cpoints, edgecolors='k')
    plt.title('point colors')

    plt.subplot(122)
    plt.tripcolor(triang, facecolors=Cfaces, edgecolors='k')
    plt.title('facecolors') 
Example 9
Project: BERNAISE   Author: gautelinga   File: plot.py    MIT License 6 votes vote down vote up
def plot_faces(coords, faces, face_values=None, title=None,
               clabel=None, colorbar=True, save=None, show=True,
               latex=False):
    """ Plot a mesh with values given at faces. """
    if face_values is None:
        colors = np.arange(len(faces))
        clabel = "Face number"
    else:
        colors = face_values
    fig = Figure(title=title, clabel=clabel, colorbar=colorbar,
                 save=save, show=show, latex=latex)
    fig.colorbar_ax = plt.tripcolor(coords[:, 0], coords[:, 1], faces,
                                    facecolors=colors, edgecolors='k')
    ax = plt.gca()
    ax.set_xlim([coords[:, 0].min(), coords[:, 0].max()])
    ax.set_ylim([coords[:, 1].min(), coords[:, 1].max()])
    return fig 
Example 10
Project: tectosaur   Author: tbenthompson   File: okada.py    MIT License 5 votes vote down vote up
def plot_results(self, soln, okada_soln):
        pts, tris = self.all_mesh
        est = self.get_pt_soln(soln)

        vmax = np.max(okada_soln)
        for d in range(3):
            plt.figure()
            plt.tripcolor(
                pts[:,0], pts[:, 1], tris,
                est[:,d], #shading='gouraud',
                cmap = 'PuOr', vmin = -vmax, vmax = vmax
            )
            plt.title("u " + ['x', 'y', 'z'][d])
            plt.colorbar()

        for d in range(3):
            plt.figure()
            plt.tripcolor(
                pts[:, 0], pts[:, 1], tris,
                okada_soln[:, d], #shading='gouraud',
                cmap = 'PuOr', vmin = -vmax, vmax = vmax
            )
            plt.title("Okada u " + ['x', 'y', 'z'][d])
            plt.colorbar()

        for d in range(3):
            plt.figure()
            plt.tripcolor(
                pts[:, 0], pts[:, 1], tris,
                okada_soln[:, d] - est[:,d], #shading='gouraud',
                cmap = 'PuOr'
            )
            plt.title("Diff u " + ['x', 'y', 'z'][d])
            plt.colorbar()

        plt.show() 
Example 11
Project: tectosaur   Author: tbenthompson   File: basin.py    MIT License 5 votes vote down vote up
def plot_surf_disp(country_mesh, soln):
    obs_pts, vals = country_mesh.extract_pts_vals('surf', soln)

    vmax = np.max(vals)
    for d in range(3):
        plt.figure()
        plt.tripcolor(
            obs_pts[:,0], obs_pts[:, 1], country_mesh.get_piece_tris('surf'),
            vals[:,d], #shading='gouraud',
            cmap = 'PuOr', vmin = -vmax, vmax = vmax
        )
        plt.title('u ' + ['x', 'y', 'z'][d])
        plt.colorbar()
    plt.show() 
Example 12
Project: tectosaur   Author: tbenthompson   File: inverse_tools.py    MIT License 5 votes vote down vote up
def plot_side_of_fault(m, side, view_R = 1.0):
    fC, R = get_fault_centered_view(m)

    C = np.ones(m.pts.shape[0])
    plt.figure(figsize = (10, 10))
    for i in range(3):
        which_tris = m.tris[side == i + 1]
        if which_tris.shape[0] == 0:
            continue
        plt.tripcolor(m.pts[:,0], m.pts[:,1], which_tris, C * i, vmin = 0, vmax = 3, cmap = 'hsv')
    vW = view_R * R
    plt.xlim([fC[0] - view_R * R, fC[0] + view_R * R])
    plt.ylim([fC[1] - view_R * R, fC[1] + view_R * R])
    plt.show() 
Example 13
Project: colorio   Author: nschloe   File: _tools.py    MIT License 5 votes vote down vote up
def _plot_rgb_triangle(xy_to_2d, bright=True):
    # plot sRGB triangle
    # discretization points
    n = 50

    # Get all RGB values that sum up to 1.
    rgb_linear = numpy.array(partition(3, n)).T / n
    if bright:
        # For the x-y-diagram, it doesn't matter if the values are scaled in any way.
        # After all, the tranlation to XYZ is linear, and then to xyY it's (X/(X+Y+Z),
        # Y/(X+Y+Z), Y), so the factor will only be present in the last component which
        # is discarded. To make the plot a bit brighter, scale the colors up as much as
        # possible.
        rgb_linear /= numpy.max(rgb_linear, axis=0)

    srgb_linear = SrgbLinear()
    xyz = srgb_linear.to_xyz100(rgb_linear)
    xyy_vals = xy_to_2d(_xyy_from_xyz100(xyz)[:2])

    # Unfortunately, one cannot use tripcolors with explicit RGB specification
    # (see <https://github.com/matplotlib/matplotlib/issues/10265>). As a
    # workaround, associate range(n) data with the points and create a colormap
    # that associates the integer values with the respective RGBs.
    z = numpy.arange(xyy_vals.shape[1])
    rgb = srgb_linear.to_srgb1(rgb_linear)
    cmap = matplotlib.colors.LinearSegmentedColormap.from_list(
        "gamut", rgb.T, N=len(rgb.T)
    )

    triang = matplotlib.tri.Triangulation(xyy_vals[0], xyy_vals[1])
    plt.tripcolor(triang, z, shading="gouraud", cmap=cmap)
    return 
Example 14
Project: cplot   Author: nschloe   File: main.py    MIT License 5 votes vote down vote up
def tripcolor(triang, z, alpha=1):
    rgb = get_srgb1(z, alpha=alpha)

    # https://github.com/matplotlib/matplotlib/issues/10265#issuecomment-358684592
    n = z.shape[0]
    z2 = numpy.arange(n)
    cmap = matplotlib.colors.LinearSegmentedColormap.from_list("mymap", rgb, N=n)
    plt.tripcolor(triang, z2, shading="gouraud", cmap=cmap)
    return 
Example 15
Project: SolidsPy   Author: AppliedMechanics-EAFIT   File: postprocesor.py    MIT License 5 votes vote down vote up
def tri_plot(tri, field, title="", levels=12, savefigs=False,
             plt_type="contourf", filename="solution_plot.pdf"):
    """Plot contours over triangulation

    Parameters
    ----------
    tri : ndarray (float)
        Array with number and nodes coordinates:
        `number coordX coordY BCX BCY`
    field : ndarray (float)
        Array with data to be plotted for each node.
    title : string (optional)
        Title of the plot.
    levels : int (optional)
        Number of levels to be used in ``contourf``.
    savefigs : bool (optional)
        Allow to save the figure.
    plt_type : string (optional)
        Plot the field as one of the options: ``pcolor`` or
        ``contourf``
    filename : string (optional)
        Filename to save the figures.
    """
    if plt_type == "pcolor":
        disp_plot = plt.tripcolor
    elif plt_type == "contourf":
        disp_plot = plt.tricontourf
    disp_plot(tri, field, levels, shading="gouraud")
    plt.title(title)
    plt.colorbar(orientation='vertical')
    plt.axis("image")
    if savefigs:
        plt.savefig(filename) 
Example 16
Project: tectosaur   Author: tbenthompson   File: okada.py    MIT License 4 votes vote down vote up
def build_constraints(surface_tris, fault_tris, pts, tris, gauss_z):
    n_surf_tris = surface_tris.shape[0]
    n_fault_tris = fault_tris.shape[0]

    side = get_side_of_fault(pts, tris, surface_tris.shape[0])

    # plt.tripcolor(pts[:,0], pts[:,1], tris[:surface_tris.shape[0]], side[:surface_tris.shape[0]])
    # plt.triplot(pts[:,0], pts[:,1], tris[surface_tris.shape[0]:], 'k-')
    # plt.show()

    from tectosaur.constraints import build_constraint_matrix
    cs = continuity_constraints(pts, tris, surface_tris.shape[0])
    slip = gauss_fault_slip(pts, fault_tris, gauss_z).flatten()
    cs.extend(all_bc_constraints(
        n_surf_tris, n_surf_tris + n_fault_tris, slip
    ))
    # cm = build_constraint_matrix(cs, tris.shape[0] * 9)
    # import ipdb
    # ipdb.set_trace()


    # import copy
    # cs2 = copy.copy(cs)
    # csf_idxs = [i for i in range(len(cs2)) if len(cs2[i].terms) == 3]
    # from tectosaur.constraints import ConstraintEQ, Term
    # xs = []
    # ys = []
    # for i in csf_idxs:
    #     old_c = cs2[i]
    #     fault_dof = old_c.terms[2].dof
    #     slip_val = slip[fault_dof - n_surf_tris * 9]
    #     if fault_dof % 3 == 0:
    #         corner_idx = (fault_dof // 3) % 3
    #         tri_idx = (fault_dof - corner_idx * 3) // 9 - n_surf_tris
    #         x = pts[fault_tris[tri_idx, corner_idx], 0]
    #         xs.append(x)
    #         ys.append(slip_val)
    #     new_c = ConstraintEQ(old_c.terms[:2], slip_val * -old_c.terms[2].val)
    #     cs2[i] = new_c
    # from tectosaur.constraints import build_constraint_matrix
    # cm, c_rhs = build_constraint_matrix(cs, tris.shape[0] * 9)
    # cm2, c_rhs2 = build_constraint_matrix(cs2, tris.shape[0] * 9)
    # plt.plot(c_rhs, 'k-')
    # plt.plot(c_rhs2, 'b-')
    # plt.show()
    # import ipdb
    # ipdb.set_trace()

    return cs 
Example 17
Project: pymcfost   Author: cpinte   File: disc_structure.py    MIT License 4 votes vote down vote up
def add_spiral(
        self, a=30, sigma=10, f=1, theta0=0, rmin=None, rmax=None, n_az=None
    ):
        """ Add a geometrucal spiral on a 2D (or 3D) mcfost density grid
        and return a 3D array which can be directly written as a fits
        file for mcfost to read

        geometrical spiral r = a (theta - theta0)
        surface density is mutiply by f at the crest of the spiral
        the spiral has a Gaussin profil in (x,y) with sigma given in au
        """

        if self.grid.ndim <= 2:
            ValueError("Can only add a spiral on a cylindrical or spherical grid")

        if n_az is None:
            n_az = self.grid.shape[1]
        phi = np.linspace(0, 2 * np.pi, n_az, endpoint=False)

        r = self.grid[0, 0, 0, :]

        if rmin is None:
            rmin = r.min()
        if rmax is None:
            rmax = r.max()

        x = r[np.newaxis, :] * np.cos(phi[:, np.newaxis])
        y = r[np.newaxis, :] * np.sin(phi[:, np.newaxis])

        # Just to test
        # x = np.linspace(-100,100,500)
        # x, y = np.meshgrid(x,x)
        # r = np.sqrt(x**2 + y**2) # we recalcule in preparation for other types of grid

        # rc=50, hc=0.15, alpha=1.5, beta=0.25
        # theta_c = 0.
        # theta = theta_c + np.sign(r - rc)/hc * \
        #        ((r/rc)**(1+beta) * (1/(1+beta) - 1/(1-alpha + beta) * (r/rc)**(-alpha)) \
        #         - 1/(1+beta) - 1/(1-alpha + beta))

        r_spiral = np.geomspace(rmin, rmax, num=5000)
        theta = r_spiral / a + theta0

        x_spiral = r_spiral * np.cos(theta)
        y_spiral = r_spiral * np.sin(theta)

        correct = np.ones(x.shape)

        # This is really badly implemented, but fast enough that we don't care
        sigma2 = sigma ** 2
        for i in range(x.shape[0]):
            for j in range(x.shape[1]):
                d2 = np.min((x_spiral - x[i, j]) ** 2 + (y_spiral - y[i, j]) ** 2)
                correct[i, j] += f * np.exp(-0.5 * d2 / sigma2)

        triang = tri.Triangulation(x.flatten(), y.flatten())
        plt.tripcolor(triang, correct.flatten(), shading='flat')

        return self.gas_density[np.newaxis, :, :] * correct[:, np.newaxis, :]