2

I have three 2d arrays: X,Y,Z, which contain irregular 3d points coordinate,respectively.And another 2d array data, which contains the values on those points. What I want to do is to display this data in 3d space , with 0 value part masked out.Much like this one:

enter image description here

In matlab, I can use function fill3 to achieve this, but how can I plot the same kind of picture in matplotlib or mayavi ? I have tried to use mask array ,plot_surface and colorface together, as the example here: Plotting a masked surface plot using python, numpy and matplotlib

and it worked, the result is the link below:

enter image description here but that is really really slow, and will cost too much time. Is there a better way?

Community
  • 1
  • 1
viczhn
  • 21
  • 4
  • The coordinate array are irregular distribution ! e.g.: X=[0.1,0.2,5,-1,-2] Y=[1,2,1.4,0,-5] Z=[10,15,9,20,13] – viczhn Feb 12 '15 at 16:28
  • My OCD forces me to hate with all my strength those non-perpendicular looking axis in matplotlib. – Ander Biguri Feb 12 '15 at 18:02

1 Answers1

0

Well, today I find out an alternative way to solve the problem. Except using plot_surface, I choose to use scatter3D, the core code is some what like this aa=np.shape(X)[0] bb=np.shape(X)[1] x=X.reshape(aa*bb) y=Y.reshape(aa*bb) z=Z.reshape(aa*bb) data=data.reshape(aa*bb) x1=[] y1=[] z1=[] da1=[] for i in range(aa*bb): if data[i]>0: x1.append(x[i]) y1.append(y[i]) z1.append(z[i]) da1.append(data[i]) my_cmap=cm.jet my_cmap.set_over('c') my_cmap.set_under('m') N=da1/max(da1) fig=plt.figure() ax=fig.add_subplot(111,projection='3d') ax.scatter3D(x1,y1,z1,s=6,alpha=0.8,marker=',',facecolors=my_cmap(N),lw=0)

and the result is like this:

enter image description here

this doesn't really solve the problem, but it is a nice substitution. I'll keep waiting for more answers.

viczhn
  • 21
  • 4