python - 非均匀间隔数据的热图

标签 python matplotlib plot heatmap

我想使用 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 中创建这样的插值图?

enter image description here

最佳答案

您应该插入缺失的数据,我在以下项目之一中使用过:

#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/

相关文章:

python - 理解 Python 交换 : why is a, b = b, a 并不总是等价于 b, a = a, b?

python - 在 matplotlib 中使用轴对象设置事件子图?

python - 防止 x 轴标签在 matplotlib/pyplot 中被截断

r - 将轴刻度标签格式化为绘图中的百分比

python - Django 迁移不会更改 AWS Elastic Beanstalk 中的数据库

python - 标签 python 内的部分文本

python - matplotlib "axis.invert_xaxis"使用日期时间时崩溃

matlab - MATLAB 中数据周围的椭圆

algorithm - 比较绘图的最快方法

python - 木星 SSL : WRONG_VERSION_NUMBER