python - Plot 3D mesh using mplot3d -


starting text file containing points coordinates of 3d surface, deformed due pressure applied on , values of pressure applied according following example:

 node_label           x_in           y_in           z_in          x_def          y_def          z_def         press        11542          15229          17734          18332        11.4645        67.7709        138.905    4.97573e-03       11543           3283           3238          16784        7.73624        67.3238        138.781    13.2628e-03       11540          13506          13385          17482        18.9023        67.6291        139.051    3.61705e-03       11541           7637           7516          18637        15.2164        68.0038        139.031    12.7343e-03       11546          16137          16651          16886       -2.98896        66.1776        138.431    19.0185e-03       11547           7360           7361          16903       -6.42838        65.3547        138.177    2.74949e-03        ....           ....           ....           ....           ....           ....           ....            .... 

i trying plot 3d surface + deformed, colored contour plot of pressure on deformed surface using mplot3d library. here code:

from tkinter import tk tkfiledialog import askopenfilename, asksaveasfile mpl_toolkits.mplot3d import axes3d import matplotlib.pyplot plt matplotlib import cm matplotlib.ticker import linearlocator, formatstrformatter import numpy np  tk().withdraw()   f_in = askopenfilename(title='choose txt file')   x_in = [] y_in = [] z_in = [] x_def = [] y_def = [] z_def = [] cpress = []  open(f_in,"r") f0:      ind, line in enumerate(f0):           if ind > 2:                item = line.strip()                 if item:                     item = item.split()                 x_in.append(item[0])                y_in.append(item[1])                z_in.append(item[2])                x_def.append(item[3])                y_def.append(item[4])                z_def.append(item[5])                cpress.append(item[6])  fig = plt.figure() ax = fig.gca(projection='3d')  x_in = np.asarray(x_in) y_in = np.asarray(y_in) z_in = np.asarray(z_in)  surf = ax.plot_surface(x_in, y_in, z_in, cmap=cm.coolwarm,                        linewidth=0, antialiased=false) plt.show() 

but not plot anything.

from @importanceofbeingernest comentary, using plot_trisurf:

[...] open(f_in,"r") f0:     ind, line in enumerate(f0):         if ind > 2:             item = line.strip()             if item:                 item = item.split()                 #node_label = item[0]                 x_in.append(item[1])                 y_in.append(item[2])                 z_in.append(item[3])                 x_def.append(item[4])                 y_def.append(item[5])                 z_def.append(item[6])                 cpress.append(item[7])  # type important convert strings numbers: x_in = np.asarray(x_in, dtype=np.float64) y_in = np.asarray(y_in, dtype=np.float64) z_in = np.asarray(z_in, dtype=np.float64)  fig = plt.figure() ax = fig.gca(projection='3d')  points = ax.scatter(x_in, y_in, z_in, cmap=cm.coolwarm, antialiased=false)  surface = ax.plot_trisurf(x_in, y_in, z_in, cmap=cm.coolwarm, antialiased=false)  fig.tight_layout() fig.show() 

enter image description here


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -