How To Smooth By Interpolation When Using Pcolormesh?
I have a basemap of the world, and it's filled with data (lintrends_mean) using pcolormesh. Because the data has relatively large grid boxes, I'd like to smooth the plot. However,
Solution 1:
You have some variants:
- Use special shading for
pcolormesh
. - Use
imshow
which allows to interpolated data. - Interpolate data with
scipy.interpolate
and plot withpcolormesh
.
Look at the example:
import matplotlib.pylab as plt
import numpy as np
from scipy.interpolate import interp2d
data = np.random.random((30,30))
X = np.arange(0, 30, 1)
Y = np.arange(0, 30, 1)
X, Y = np.meshgrid(X, Y)
# colormesh original
plt.subplot(3, 2, 1)
plt.pcolormesh(X, Y, data, cmap='RdBu')
# pcolormesh with special shading
plt.subplot(3, 2, 2)
plt.pcolormesh(X, Y, data, cmap='RdBu',shading='gouraud')
# imshow bilinear interp.
plt.subplot(3, 2, 3)
plt.imshow(data, cmap='RdBu', interpolation = 'bilinear')
# imshow bicubic interp.
plt.subplot(3, 2, 4)
plt.imshow(data, cmap='RdBu', interpolation = 'bicubic')
# scipy interp. cubic
f = interp2d(X, Y, data, kind='cubic')
xnew = np.arange(0, 30, .1)
ynew = np.arange(0, 30, .1)
data1 = f(xnew,ynew)
Xn, Yn = np.meshgrid(xnew, ynew)
plt.subplot(3, 2, 5)
plt.pcolormesh(Xn, Yn, data1, cmap='RdBu')
plt.show()
Post a Comment for "How To Smooth By Interpolation When Using Pcolormesh?"