I have three 3D mesh matrices (X, Y, Z) corresponding to the xyz coordinate space.
I also have a 3D Numpy matrix A where A[i,j,k] contains a float that is associated with the point (x,y,z) where x=X[i,j,k], y=Y[i,j,k], and z=Z[i,j,k]. The float values are continuous within A (i.e. the change in value between adjacent elements of A are typically small).
Is there a way to plot the surface that corresponds to a given float value in A using Matplotlib or any other Python-based graphics package? For example, if given a value 2.34, I am interested in getting a plotted contour surface of the matrix A wherever 2.34 (plus or minus some tolerance) shows up?
So far, I have been able to recover the xyz coordinates of all values in A that are within some tolerance of the target value and then make a 3D scatter plot using this (code below). Perhaps there is also a way of plotting a surface from these points?
def clean (A, t, dt):
# function for making A binary for t+-dt
# t is the target value I want in the matrix A with tolerance dt
new_A = np.copy(A)
new_A[np.logical_and(new_A > t-dt, new_A < t+dt)] = -1
new_A[new_A != -1] = 0
new_A[new_A == -1] = 1
return (new_A)
def get_surface (X, Y, Z, new_A):
x_vals = []
y_vals = []
z_vals = []
# Retrieve (x,y,z) coordinates of surface
for i in range(new_A.shape[0]):
for j in range(new_A.shape[1]):
for k in range(new_A.shape[2]):
if new_A[i,j,k] == 1.0:
x_vals.append(X[i,j,k])
y_vals.append(Y[i,j,k])
z_vals.append(Z[i,j,k])
return (np.array(x_vals), np.array(y_vals), np.array(z_vals))
cleaned_A = clean (A, t=2.5, dt=0.001)
x_f, y_f, z_f = get_surface (X, Y, Z, cleaned_A )
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d', aspect='equal')
ax.scatter(x_f, y_f, z_f, color='g', s=1)
I have also tried ax.plot_trisurf(x_f,y_f,z_f), but this gives me an poorly connected plot. I'm guessing that the ordering of values in my arrays might be affecting this, in which case is there a package that can do some kind of 3D interpolated surface plot with random ordering of points (e.g. through minimizing the surface area or something like that?)
The object that I am interested in is roughly spherical (i.e. two z's per (x,y)). I can't seem to find any working examples of someone triangulating over a closed 3D surface, but maybe I'm not looking in the right places.
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)