我正在尝试使用pcolormesh shading =' gouraud'来平滑我的颜色贴图。参数,但它失败了,返回了跟随错误,我不明白。
"/usr/local/anaconda/lib/python2.7/site- packages/matplotlib/collections.py", line 1822, in draw
gc, triangles, colors, transform.frozen())
File "/usr/local/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_ps.py", line 876, in draw_gouraud_triangles
('colors', 'u1', (3,))])
TypeError: data type not understood File
我的代码如下:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rcParams
from matplotlib.mlab import griddata
from matplotlib.ticker import AutoMinorLocator
from mpl_toolkits.axes_grid1 import make_axes_locatable
from mpl_toolkits.basemap import Basemap
x = np.loadtxt('data.txt',usecols=[0])
y = np.loadtxt('data.txt',usecols=[1])
s = np.loadtxt('data.txt',usecols=[2])
N = 36j
M = 18j
extent = (min(x), max(x), min(y), max(y))
xx,yy = np.mgrid[extent[0]:extent[1]:N, extent[2]:extent[3]:M]
ss = griddata(x, y, s, xx, yy, interp='linear')
fig, ax = plt.subplots()
#m = Basemap(projection='hammer',lon_0=0,resolution=None)
m = Basemap(projection='kav7',lon_0=0,resolution=None)
m.drawmapboundary(fill_color='0.75')
im = m.pcolormesh(xx,yy,ss,shading='gouraud',cmap=plt.cm.jet,latlon=True)
m.drawparallels(np.arange(-90.,99.,30.))
m.drawmeridians(np.arange(-180.,180.,60.))
cb = m.colorbar(im,"bottom", size="5%", pad="2%", ticks=[-2,-1,0,1,2,3,4,5])
plt.show()
当着色参数为平面shading = 'flat'
时,这种效果非常好,但颜色并不平滑。任何人都可以告诉我如何解决这个问题?