1

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

enter image description here

Can I apply any filter on this?

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Sylvain
  • 253
  • 2
  • 7
  • 18
  • `imshow` doesn't seem to have a smooth option, so you should probably look into smoothing of the dataset itself. See e.g. [this](http://stackoverflow.com/questions/14765891/image-smoothing-in-python) example – Bart Dec 11 '15 at 18:48
  • The new default interpolation in mpl 2.0 will be `'nearest'` – tacaswell Dec 13 '15 at 05:12
  • @tcaswell Is it really a duplicate? Although I agree that the solution is the same, I would argue that the question asked here is not duplicate of the one you reference. I can easily imagine someone searching for one of them might not find the other based on the question asked. – M.T Dec 13 '15 at 20:45

1 Answers1

11

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

matplotlib demo

matplotlib api output

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): enter image description here

M.T
  • 4,917
  • 4
  • 33
  • 52