Functional, Datagrid and Meshgrid Line wireframe plotsΒΆ
This is a comparison among wireframe plots using line objects constructed from either functional, Datagrid or Meshgrid methods for 3D visualization of data values at xy positions.
Surface geometry is that taken from the matplotlib 3D wireframe plot example.
Functional
Pros
Most useful when data can be represented functionally.
No need for additional data arrays.
Data line can smooth at any rez.
Line rez independently controlled along the x or y axis.
Cons
The starting normalized coordinates require scaling.
Datagrid
Pros
Data is automatically normalized.
Data line can smooth at any rez.
Line rez independently controlled along the x or y axis.
Cons
Line smoothing dependent of datagrid data.
The starting normalized coordinates may require scaling.
Meshgrid
Pros
Grid resolution is set by the resolution of the data.
Grid scaling is automatic.
Cons
Line smoothing is not optional, straight segment length dependent on the data resolution.
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
import s3dlib.surface as s3d
#.. Matplotlib Examples: Wireframe line plots
# 1. Define function to examine .....................................
def get_normalized_test_data(xyz,delta=0.05):
x,y,z = xyz
X,Y = 3*x, 3*y
Z1 = np.exp(-(X**2 + Y**2) / 2) / (2 * np.pi)
Z2 = (np.exp(-(((X - 1) / 1.5)**2 + ((Y - 1) / 0.5)**2) / 2) /
(2 * np.pi * 0.5 * 1.5))
Z = Z2 - Z1
return x,y,Z
X, Y, Z = axes3d.get_test_data()
# 2. Setup and map surfaces .........................................
rez=5
# method 1: direct functional definition..............
norm_line = s3d.ParametricLine(rez, name="functional")
norm_line.map_xySlice_from_op( get_normalized_test_data, xset=18, yset=18 )
norm_line.transform(scale=[30,30,500])
# method 2: datagrid method .........................
data_line = s3d.ParametricLine(rez, name="datagrid")
data_line.map_xySlice_from_datagrid(Z, xset=18, yset=18)
data_line.scale_dataframe(X,Y,Z)
# method 3: meshgrid method .........................
p = int(Z.shape[0]/16)
region = np.s_[::p,::p]
x,y,z = X[region], Y[region], Z[region]
mesh_line = s3d.ParametricLine.meshgrid(x,y,z, name="meshgrid")
# 3. Construct figure, add surface, plot ............................
lines = [ norm_line, data_line, mesh_line ]
fig = plt.figure(figsize=plt.figaspect(0.3))
for i,line in enumerate(lines) :
fig.text(0.17+0.333*i,0.88, str(line),va='bottom',ha='center')
ax = fig.add_subplot(1,3,i+1, projection='3d')
ax.set(xlim=(-30,30), ylim=(-30,30), zlim=(-60,80) )
ax.set_xticks(np.arange(-30, 40, 10))
ax.set_yticks(np.arange(-30, 40, 10))
ax.set_zticks(np.arange(-60, 90, 20))
ax.set_title(line.name + ' - Lines', fontsize='xx-large')
ax.add_collection3d(line)
fig.tight_layout()
plt.show()