我想使用 matplotlib 创建一个热图,如下所示。从轴刻度中可以看出,数据的间隔不均匀。 所以假设我们有
x = [1, 1.5, 2, 2.5, 3, 3.5, 4, 5, 7]
y = [.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5]
vals = np.random.rand(len(x), len(y))
如何在 matplotlib 中创建这样的插值图?
最佳答案
您应该插入缺失的数据,我在以下项目之一中使用过:
#create regular grid
xi, yi = np.linspace(x.min(), x.max(), 100), np.linspace(y.min(), y.max(), 100)
xi, yi = np.meshgrid(xi, yi)
#interpolate missing data
rbf = scipy.interpolate.Rbf(x, y, z, function='linear')
zi = rbf(xi, yi)
关于python - 非均匀间隔数据的热图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39034797/