我正在尝试创建一个二维高斯函数的简单 imshow() 图(matplotlib v.1.2.1):
import matplotlib.pyplot as plt
import numpy as np
from pylab import *
def gaussian(x,y,stdx,stdy):
return 1.0/(2*np.pi*stdx*stdy) * (np.exp(-0.5*(x**2/stdx**2 + y**2/stdy**2)))
coords = np.linspace(-1,1,100)
X,Y = np.meshgrid(coords,coords)
std_list = np.linspace(1,2,20)
output = [gaussian(X,Y,std_list[i],std_list[i]) for i in range(len(std_list))]
for i in range(len(output)):
plt.imshow(X,Y,np.array(output[i]),cmap='bone')
plt.show()
我收到以下错误:
Traceback (most recent call last):
File "blur.py", line 14, in <module>
plt.imshow(X,Y,np.array(output[i]),cmap='bone')
TypeError: imshow() got multiple values for keyword argument 'cmap'
事实上,为了确保我没有发疯,我完全去掉了 cmap 参数,现在我收到以下错误:
Traceback (most recent call last):
File "blur.py", line 14, in <module>
plt.imshow(X,Y,np.array(output[i]))
File "/home/username/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py", line 2737, in imshow
imlim=imlim, resample=resample, url=url, **kwargs)
File "/home/username/anaconda/lib/python2.7/site-packages/matplotlib/axes.py", line 7098, in imshow
if norm is not None: assert(isinstance(norm, mcolors.Normalize))
AssertionError
我已经确保 imshow( ) 的参数都具有相同的形状,所以我不完全确定我做错了什么。这可能是一个错误吗?