Matplotlib:阿尔法绘制三维数据 [英] Matplotlib: Plot 3d data with alpha

查看:305
本文介绍了Matplotlib:阿尔法绘制三维数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3D数据,即 data.shape =(N,N,N)。什么我打算做的是绘制在3D这个数据,用不同的颜色来反映的数据值[X,Y,Z] 。如果某些值是下一个门槛我想这点是完全不可见的(阿尔法= 0 )。因此,在这个意义上,我要寻找一个三维轮廓图。

I have 3D data, i.e. data.shape=(N,N,N). What I am planning to do is to plot this data in 3D, using different colors to reflect the value of data[x,y,z]. If some value is under a threshold I want this point to be fully invisible (alpha=0). So in this sense I am looking for a "3D contour plot".

这甚至可能与matplotlib?

Is this even possible with matplotlib?

感谢您的任何建议。

我发现用数学中的一个解决方案 ListContourPlot3D 。如果有一个相当于matplotlib请让我知道,谢谢

I have found a solution in mathematica using ListContourPlot3D. If there is an equivalent for matplotlib please let me know, thanks

推荐答案

它当然是可能的,请参阅下面的地方3 n×m个网格在彼此上方绘制的例子。注意,中间的一个已掩蔽数据(在这种情况下)高于某个阈值。阿尔法可以通过使用颜色表的cmap.set_bad()属性来控制。

Its certainly possible, see the example below where 3 nxm grids are plotted above each other. Notice that the middle one has masked data (in this case) above a certain threshold. The alpha can be controlled by using the cmap.set_bad() property of a colormap.

from mpl_toolkits.mplot3d import Axes3D
import mpl_toolkits.mplot3d.art3d as art3d
import numpy as np
import matplotlib.pyplot as plt 

fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')
fig.text(.5,.9, 'Fancy plot', ha='center', size=14)

ax.set_xticklabels([])
ax.set_yticklabels([])
ax.set_zticklabels([])

cmap=plt.cm.RdYlGn
cmap.set_bad('white', alpha=0)

p = ax.pcolor(x, y, ndvi1data, cmap=cmap)
art3d.poly_collection_2d_to_3d(p, 0)

q = ax.pcolor(x, y, np.ma.masked_where(ndvi2data>100,ndvi2data), cmap=cmap)
art3d.poly_collection_2d_to_3d(q, 5)

o = ax.pcolor(x, y, ndvi3data, cmap=cmap)
art3d.poly_collection_2d_to_3d(o, 10)

ax.set_xlim([x[0,0], x[-1,0]])
ax.set_ylim([y[0,0], y[0,-1]])
ax.set_zlim([0,10])

fig.colorbar(p)

这篇关于Matplotlib:阿尔法绘制三维数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆