How to plot 3D data as 2D grid colormap in Python?

两盒软妹~` 提交于 2019-12-04 13:01:45

You can use griddata from matplotlib.mlab to grid your data properly.

import numpy as np
from matplotlib.mlab import griddata

x = np.array([0,0,1,1])
y = np.array([0,1,0,1])
z = np.array([0,10,20,30])
xi = np.arange(x.min(),x.max()+1)
yi = np.arange(y.min(),y.max()+1)
ar = griddata(x,y,z,xi,yi)

# ar is now
# array([[  0.,  20.],
#        [ 10.,  30.]])

The choice of the mapped xi and yi points is up to you, and they do not have to be integers as griddata can interpolate for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!