Search code examples
pythonmatplotlibplotsmoothingcontourf

How to make the figure look clear after smoothing?


I make a plot using pcolormesh and it turns out like this:

enter image description here

Then, I tried to set the argument shading = 'gouraud', but the result looks blurry:

enter image description here

To make the picture clear, I also tried to interpolate the data to a smaller meshgrid. Unfortunately, it doesn' work.

So I want to know what I should do to make my plot looks smoother and clearer.


Solution

  • Here I use a gaussian filter to smooth the data and make the plot look clearer.

    First, plot the original data, plt.pcolormesh(x, Y, Z), and the result shows:

    enter image description here

    Then, let the data pass through a gaussian filter Z2 = ndimage.gaussian_filter(Z, sigma=1.0, order=0). And plot the result plt.contourf(X, Y, Z2, levels = 10) to give:

    enter image description here

    This would make the figure look clear while capturing the main distribution features of the data.

    Hope it helps!