是否可以将数据数组(numpy数组)传递给交互功能?
我的数据从csv文件bad.csv加载并存储到numpy数组中:例如u
,v
,w
和uNorm
。
我试图在没有运气的情况下使用以下代码段:
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.tri as mtri
import numpy as np
from IPython.html.widgets import interact, fixed
fileName = './bad.csv'
p,u,v,w,x,y,z = np.loadtxt(fileName,delimiter=',',skiprows=1,usecols=(0,1,2,3,4,5,6),unpack=True)
uNorm = np.sqrt(u**2 + v**2 + w**2)
r = np.sqrt(y**2 + x**2)
tang = (y / x)
aux_tri = mtri.Triangulation(r/np.max(r), tang/np.max(tang))
triang = mtri.Triangulation(x, y, aux_tri.triangles)
triang.set_mask(mtri.TriAnalyzer(aux_tri).get_flat_tri_mask())
def plotContour(data=w, legendName='Legend', gridOn=True, edgeColors='black'):
plt.gca().set_aspect('equal')
plt.tripcolor(triang,data,NbLevels,cmap=cm.hot_r,edgecolors=edgeColors)
plt.grid(gridOn)
cbar = plt.colorbar()
cbar.set_label(legendName,labelpad=10)
interact(plotContour, data={'u':fixed(u),'v':fixed(v),'w':fixed(w),'Magnitude':fixed(uNorm)}, edgeColors=('Black','None'));
第一次运行此代码段时,一切正常,因为data
的默认值为w
。
但是当我尝试使用下拉菜单时,我收到以下错误:
/usr/local/lib/python2.7/dist-packages/matplotlib/tri/tripcolor.pyc in tripcolor(ax, *args, **kwargs)
74 # length of C whether it refers to points or faces.
75 # Do not do this for gouraud shading.
---> 76 if (facecolors is None and len(C) == len(tri.triangles) and
77 len(C) != len(tri.x) and shading != 'gouraud'):
78 facecolors = C
TypeError: len() of unsized object
那么如何在下拉菜单中传递numpy数组?