Пример #1
0
            indices.append(i * (slices) + j + 1)
            indices.append(i * (slices) + j + slices + 1)
            indices.append(i * (slices) + j + slices)
            c = (i + j) % 2
            colors.append([c, c, c, 1 - c * 0.1])
    indices = np.array(indices).reshape(-1, 4)
    return vertices, indices, np.array(colors).reshape(-1, 4)


# --- main --------------------------------------------------------------------
if __name__ == "__main__":
    import matplotlib.pyplot as plt

    fig = plt.figure(figsize=(4, 4))
    ax = fig.add_axes([0, 0, 1, 1], xlim=[-1, +1], ylim=[-1, +1], aspect=1)
    ax.axis("off")

    camera = Camera("perspective", 145, 35, scale=1)
    vertices, faces, facecolors = sphere(0.75)
    mesh = Mesh(ax,
                camera.transform,
                vertices,
                faces,
                facecolors=facecolors,
                edgecolors="white",
                mode="all")
    camera.connect(ax, mesh.update)

    plt.savefig("checkered-sphere.png", dpi=600)
    plt.show()
Пример #2
0
    V, Vi = [], []
    with open(filename) as f:
       for line in f.readlines():
           if line.startswith('#'): continue
           values = line.split()
           if not values: continue
           if values[0] == 'v':
               V.append([float(x) for x in values[1:4]])
           elif values[0] == 'f' :
               Vi.append([int(x) for x in values[1:4]])
    return np.array(V), np.array(Vi)-1



# --- main --------------------------------------------------------------------
if __name__ == "__main__":
    import matplotlib.pyplot as plt

    fig = plt.figure(figsize=(4,4))
    ax = fig.add_axes([0,0,1,1], xlim=[-1,+1], ylim=[-1,+1], aspect=1)
    ax.axis("off")

    camera = Camera("ortho", scale=2)
    vertices, faces = obj_load("data/bunny.obj")
    vertices = glm.fit_unit_cube(vertices)
    mesh = Mesh(ax, camera.transform, vertices, faces,
                cmap=plt.get_cmap("magma"),  edgecolors=(0,0,0,0.25))
    camera.connect(ax, mesh.update)
    plt.savefig("bunny.png", dpi=600)
    plt.show()
Пример #3
0
            self.collection.set_antialiased(False)
        else:
            self.collection.set_antialiased(True)


# -----------------------------------------------------------------------------
if __name__ == '__main__':
    import imageio

    from matplotlib.patches import Circle

    Z = imageio.imread("data/island.png")[::10, ::10, 0]
    Z = (Z - Z.min()) / (Z.max() - Z.min())
    Z += 0.05 * np.random.uniform(0, 1, Z.shape)
    Z = 0.25 * Z * Z

    cmap = plt.get_cmap("Reds")
    norm = mpl.colors.Normalize(vmin=Z.min(), vmax=Z.max())
    facecolors = cmap(norm(Z))

    fig = plt.figure(figsize=(10, 5))
    ax = fig.add_axes([0, 0, 1, 1], xlim=[-1, +1], ylim=[-1, 0], aspect=1)
    ax.axis("off")

    camera = Camera("perspective", 65, -125)
    bars = Bar(ax, camera.transform, Z, facecolors=facecolors)
    camera.connect(ax, bars.update)

    plt.savefig("bar.png", dpi=300)
    plt.show()
Пример #4
0
if __name__ == "__main__":
    import time
    import matplotlib as mpl
    import matplotlib.pyplot as plt

    fig = plt.figure(figsize=(8,8))
    ax = fig.add_axes([0,0,1,1], xlim=[-1,+1], ylim=[-1,+1], aspect=1)
    ax.axis("off")

    Z = np.load("data/st-helens-after.npy")
    Z[Z==-32767.] = 2231
    stride = 2
    Z = Z[20:-20:stride, 20:-20:stride]
    Z = (Z-Z.min())/(Z.max()-Z.min())
          
    camera = Camera("perspective", 45, 45, scale=1.25)
    cmap = plt.get_cmap("viridis")
    facecolors = cmap(Z)

    start = time.time()
    surface = Surface(ax, camera.transform, 0.3*Z, mode="all",
                      facecolors=facecolors, linewidths=0)
    elapsed = time.time() - start

    text = "{0} vertices, rendered in {1:.2f} second(s) with matplotlib"
    text = text.format(Z.size, elapsed)
    ax.text(0, 0, text, va="bottom", ha="left",
            transform=ax.transAxes, size="x-small")

    plt.savefig("elevation.png", dpi=600)
    plt.show()
Пример #5
0
# --- main --------------------------------------------------------------------
if __name__ == "__main__":
    import matplotlib.pyplot as plt

    white = (1.0, 1.0, 1.0, 0.8)
    black = (0.0, 0.0, 0.0, 1.0)

    fig = plt.figure(figsize=(8, 8))

    # Model loading
    vertices, faces = obj_load("data/bunny.obj")

    ax = subplot(221)
    ax.axis("off")
    camera = Camera("perspective", -20, 0, 1.5)
    mesh = Mesh(ax,
                camera.transform,
                vertices,
                faces,
                linewidths=.5,
                cmap=plt.get_cmap("magma"),
                edgecolors=(0, 0, 0, 0.25))
    camera.connect(ax, mesh.update)

    ortho = glm.ortho(-1, +1, -1, +1, 1, 100) @ glm.scale(2)

    ax = subplot(222)
    camera = ortho @ glm.xrotate(90)
    mesh = Mesh(ax,
                camera,
Пример #6
0
            indices.append(i * (slices) + j + slices + 1)

            indices.append(i * (slices) + j + slices + 1)
            indices.append(i * (slices) + j + slices)
            indices.append(i * (slices) + j)

    indices = np.array(indices)
    indices = indices.reshape(len(indices) // 3, 3)
    return vertices, indices


# --- main --------------------------------------------------------------------
if __name__ == "__main__":
    import matplotlib.pyplot as plt

    fig = plt.figure(figsize=(4, 4))
    ax = fig.add_axes([0, 0, 1, 1], xlim=[-1, +1], ylim=[-1, +1], aspect=1)
    ax.axis("off")

    camera = Camera("perspective", -35, 60)
    vertices, faces = sphere(0.75, 128, 128)
    facecolors = lighting(vertices[faces], (-1, 1, 1), (1, 0, 0), True)
    mesh = Mesh(ax,
                camera.transform,
                vertices,
                faces,
                facecolors=facecolors,
                linewidths=0)
    camera.connect(ax, mesh.update)
    plt.show()
Пример #7
0
# --- main --------------------------------------------------------------------
if __name__ == "__main__":
    import matplotlib.pyplot as plt

    fig = plt.figure(figsize=(4, 4))
    ax = fig.add_axes([0, 0, 1, 1], xlim=[-1, +1], ylim=[-1, +1], aspect=1)
    ax.axis("off")

    P = np.load("data/protein.npy")
    V, C, S = P["position"], P["color"], P["radius"]

    FC = np.ones((len(V), 4))
    FC[:, :3] = C
    EC = np.ones((len(V), 4))
    EC[:] = 0, 0, 0, .75
    S = 100 + S * 300
    V = glm.fit_unit_cube(V)

    camera = Camera("ortho", 55, -15, scale=2)
    scatter = Scatter(ax,
                      camera.transform,
                      V,
                      facecolors=FC,
                      edgecolors=EC,
                      sizes=S)
    camera.connect(ax, scatter.update)

    plt.savefig("protein.png", dpi=600)
    plt.show()
Пример #8
0
# on either 2D or 3D head models

# can be applied to Cohen’s D (C as done here) or
# statistical values (statscondCluster.F_obs or F_obs_plot)
# of inter-individual brain connectivity

# defining manually bad channel for viz test
epo1.info['bads'] = ['F8', 'Fp2', 'Cz', 'O2']
epo2.info['bads'] = ['F7', 'O1']

# Visualization of inter-brain connectivity in 2D
# defining head model and adding sensors
fig, ax = plt.subplots(1, 1)
ax.axis("off")
vertices, faces = viz.get_3d_heads()
camera = Camera("ortho", theta=90, phi=180, scale=1)
mesh = Mesh(ax, camera.transform @ glm.yrotate(90), vertices, faces,
            facecolors='white',  edgecolors='black', linewidths=.25)
camera.connect(ax, mesh.update)
plt.gca().set_aspect('equal', 'box')
plt.axis('off')
viz.plot_sensors_2d(epo1, epo2, lab=True)  # bads are represented as squares
# plotting links according to sign (red for positive values,
# blue for negative) and value (line thickness increases
# with the strength of connectivity)
viz.plot_links_2d(epo1, epo2, C=C, threshold=2, steps=10)
plt.tight_layout()
plt.show()

# Visualization of inter-brain connectivity in 3D
# defining head model and adding sensors
Пример #9
0
    from tessagon.misc.shapes import klein, torus
    from tessagon.types.hex_tessagon import HexTessagon
    from tessagon.adaptors.list_adaptor import ListAdaptor
    options = {
        'function': klein,
        'u_range': [0.0, 1.0], 'v_range': [0.0, 1.0],
        'u_num': 60,           'v_num': 10,
        'u_cyclic': True,      'v_cyclic': True,
                               'v_twist': True,
        'adaptor_class' : ListAdaptor
    }
    tessagon = HexTessagon(**options)
    mesh = tessagon.create_mesh()
    vertices = np.array(mesh["vert_list"])
    faces = mesh["face_list"]
    
    
    import matplotlib.pyplot as plt
    fig = plt.figure(figsize=(6,6))
    ax = fig.add_axes([0,0,1,1], xlim=[-1,+1], ylim=[-1,+1], aspect=1)
    ax.axis("off")

    camera = Camera("perspective", 65, 15, scale=2)
    vertices = glm.fit_unit_cube(vertices)
    mesh = Mesh(ax, camera.transform, vertices, faces, mode="all",
                cmap=plt.get_cmap("magma"), edgecolors=(0,0,0,0.25)) 
    camera.connect(ax, mesh.update)
    plt.savefig("klein-bottle.png", dpi=300)
    plt.show()

Пример #10
0
if __name__ == "__main__":
    import time
    import matplotlib as mpl
    import matplotlib.pyplot as plt

    fig = plt.figure(figsize=(8, 8))
    ax = fig.add_axes([0, 0, 1, 1], xlim=[-1, +1], ylim=[-1, +1], aspect=1)
    ax.axis("off")

    Z = np.load("data/st-helens-after.npy")
    Z[Z == -32767.] = 2231
    stride = 2
    Z = Z[20:-20:stride, 20:-20:stride]
    Z = (Z - Z.min()) / (Z.max() - Z.min())

    camera = Camera("perspective", 45, 45, scale=1.25)
    cmap = plt.get_cmap("viridis")
    facecolors = cmap(Z)

    start = time.time()
    surface = Surface(ax,
                      camera.transform,
                      0.3 * Z,
                      mode="all",
                      facecolors=facecolors,
                      linewidths=0)
    elapsed = time.time() - start

    text = "{0} vertices, rendered in {1:.2f} second(s) with matplotlib"
    text = text.format(Z.size, elapsed)
    ax.text(0,
Пример #11
0
                                         closed=True,
                                         linewidths=1.0,
                                         facecolors=(1, 1, 1, 0.75),
                                         edgecolors=(0, 0, 0, 1))
        self.update(transform)
        ax.add_collection(self.collection, autolim=False)

    def update(self, transform):
        V = glm.transform(self.vertices, transform)
        F = np.array([V[face] for face in self.faces])
        I = np.argsort(-np.mean(F[:, :, 2].squeeze(), axis=-1))
        verts = F[I][..., :2]
        self.collection.set_verts(verts)


# --- main --------------------------------------------------------------------
if __name__ == "__main__":
    import matplotlib.pyplot as plt
    from matplotlib.collections import PolyCollection

    fig = plt.figure(figsize=(4, 4))
    ax = fig.add_axes([0, 0, 1, 1], xlim=[-1, 1], ylim=[-1, 1], aspect=1)
    ax.axis("off")

    camera = Camera(theta=65, phi=40)
    cube = Cube(ax, camera.transform)
    camera.connect(ax, cube.update)

    plt.savefig("cube.png", dpi=600)
    plt.show()
Пример #12
0
    [+1, -1, -1],  # E
    [+1, +1, -1],  # F
    [-1, +1, -1],  # G
    [-1, -1, -1]
]  # H
faces = [
    [0, 1, 2, 3],  # ABCD: top face
    [0, 3, 4, 5],  # ADEF: right face
    [0, 5, 6, 1],  # AFGB: front face
    [1, 6, 7, 2],  # BGHC: left face
    [7, 4, 3, 2],  # HEDC: back face
    [4, 7, 6, 5]
]  # EFGH: bottom face

fig = plt.figure(figsize=(6, 6))
ax = fig.add_axes([0, 0, 1, 1], xlim=[-1, 1], ylim=[-1, 1], aspect=1)
ax.axis("off")

camera = Camera("perspective", 45, 35, scale=0.5)
vertices = glm.transform(vertices, camera.transform)
faces = np.array([vertices[face] for face in faces])
index = np.argsort(-np.mean(faces[:, :, 2].squeeze(), axis=-1))
vertices = faces[index][..., :2]

collection = PolyCollection(vertices,
                            facecolor=(1, 1, 1, .75),
                            edgecolor="black")
ax.add_collection(collection)
plt.savefig("simple-cube.png", dpi=600)
plt.show()
Пример #13
0
    vertices += 0.003 * np.random.normal(0, 1, vertices.shape)

    V = V.ravel()
    V = (V - V.min()) / (V.max() - V.min())

    cmap = plt.get_cmap("magma")
    norm = mpl.colors.Normalize(vmin=0, vmax=1)
    facecolors = cmap(norm(V))
    facecolors[:, 3] = 0.5 * V * V
    sizes = 25 + 50 * V

    fig = plt.figure(figsize=(6, 6))
    ax = fig.add_axes([0, 0, 1, 1], xlim=[-1, +1], ylim=[-1, +1], aspect=1)
    ax.axis("off")

    camera = Camera("perspective", 45, 35)
    scatter = Scatter(ax, camera.transform, vertices, sizes, facecolors)
    cube = Mesh(ax,
                camera.transform,
                np.array(cube["vertices"]) / 2,
                np.array(cube["faces"]),
                facecolors="None",
                edgecolors=(0, 0, 0, .5),
                mode="front")

    def update(transform):
        scatter.update(transform)
        cube.update(transform)

    camera.connect(ax, update)
    plt.savefig("volume.png", dpi=300)