使用 matplotlib 平滑 imshow 图 [英] smoothing imshow plot with matplotlib

查看:30
本文介绍了使用 matplotlib 平滑 imshow 图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

解决方案

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

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

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

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

I am plotting a density of counts with imshow from matplotlib.pyplot but I'd like to have a smoother plot.

Can I apply any filter on this?

解决方案

Try using the interpolation argument: ax.imshow(grid, interpolation=interp_method)

matplotlib demo

matplotlib api

If you manually want to handle how strong the filter is you could do something along the lines of (scipy.ndimage has a lot of filters)

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)

to get (from top left: raw image, sigma=1,2,3):

这篇关于使用 matplotlib 平滑 imshow 图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆