Unstructured coordinatesΒΆ

This is a 3D comparison to the 2D Unstructured coordinates Matplotlib examples.

../../_images/mp_triplot.png

Also, surfaces from datasets which include additional vertex values are shown in the Unstructured Planar Dataset example.

import numpy as np
import matplotlib.pyplot as plt
import s3dlib.surface as s3d

#.. Matplotllib Examples: tricontour(x, y, z), triplot(x, y) and tripcolor(x, y, z)

# make data:  <--- copy from matplotlib examples
np.random.seed(1)
x = np.random.uniform(-3, 3, 256)
y = np.random.uniform(-3, 3, 256)
z = (1 - x/2 + x**5 + y**3) * np.exp(-x**2 - y**2)

verts = np.array([x,y,z]).T

# 2. Setup and map surface .........................................

surface = s3d.PlanarSurface.pntsurf(verts).map_cmap_from_op(cmap='Blues')
edges = surface.edges
edges.set_color('C0')
contours = surface.contourLineSet(5)

# 3. Construct figure, add surface, and plot ......................

fig = plt.figure(figsize=(10,3))
fig.text(0.5,0.975,str(surface), ha='center', va='top', fontsize='smaller')

for i in range(3) :
    ax = fig.add_subplot(131+i, projection='3d')
    ax.set(xticks=[-3,0,3],yticks=[-3,0,3],zticks=[0,1])
    ax.tick_params(labelcolor='w')
    ax.set_proj_type('ortho')
    ax.xaxis.set_pane_color([1,1,1])
    ax.yaxis.set_pane_color([1,1,1])
    ax.zaxis.set_pane_color([1,1,1])
    s3d.auto_scale(ax,surface)
    if i==0 : ax.scatter(x,y,z, s=3, c='darkgrey')

    if True :   # <-- show 3D view..........
        ax.add_collection3d(contours if i==0 else edges.fade(0.1) if i==1 else surface.shade())
    else :      # <-- show x-y plane........
        ax.view_init(90,-90)
        ax.add_collection3d(contours if i==0 else edges if i==1 else surface)

fig.tight_layout(pad=0)

plt.show()

The 2D plot can be visualized by rotating the plot using ax.view_init(90,-90) and omitting any surface shading and edge line fading.

../../_images/mp_triplot_vi.png