仪表/指示器的热图

时间:2015-03-05 20:50:29

标签: python algorithm matplotlib heatmap

我有一组(稀疏)数据,有温度测量。使用热图,具有更多观测值的区域显示更高的值,因为热图累积了值。

有没有办法获得更多的平均值而不是总和?但也有高斯过滤的感觉。如果区域中没有数据,则首选0值(这将是透明的)。

1 个答案:

答案 0 :(得分:0)

如果您想要高斯滤镜,请参阅ndimage.gaussian_filter

以下是一个例子:

import matplotlib.pyplot as plt
import numpy as np
import scipy.ndimage

fig = plt.figure()

# Random example data with some values set to 0
im = np.random.random((10, 10))
im[im < 0.3] = 0

# Smooth image
smoothed_im = scipy.ndimage.filters.gaussian_filter(im, sigma=1)

im[im == 0] = None
plt.imshow(im, interpolation = "nearest")
plt.title("Original image")
plt.colorbar()

plt.figure()
plt.imshow(smoothed_im, interpolation = "nearest")
plt.title("Smoothed image")
plt.colorbar()

# Blank elements that were originally 0
smoothed_im[np.isnan(im)] = None
plt.figure()
plt.imshow(smoothed_im, interpolation = "nearest")
plt.title("Smoothed image with original zeros blanked")
plt.colorbar()

这会产生: