使用 matplotlib 平滑 imshow 图

smoothing imshow plot with matplotlib

我正在用 matplotlib.pyplot 中的 imshow 绘制计数密度,但我想要一个更平滑的图。

我可以对此应用任何过滤器吗?

尝试使用插值参数: ax.imshow(grid, interpolation=interp_method)

matplotlib demo

matplotlib api

如果您想手动处理过滤器的强度,您可以 做一些事情(scipy.ndimage 有很多过滤器)

from scipy.ndimage.filters import gaussian_filter
arr=np.zeros((20,20))
arr[0,:]=3
arr[0,0]=20
arr[19,19]=30
arr[10:12,10:12]=10

filtered_arr=gaussian_filter(arr, sigma)
plt.imshow(filtered_arr)

获取(从左上角开始:原始图像,sigma=1,2,3):