2013-04-09 132 views
0
hl = [(1,109),(12,212),(21,23)] 
highlightc = np.zeros([N, N]) 
c = len(highlightc) 
colour = [0.21]*c 
test = len(number_list) -c 

this = [0.21]*test 
colour.extend(this) 
colour = np.array(colour) 
colour = np.array(colour) 
print len(number_list) 
print colour 

for x, y in hl: 
    highlightc[x, y] = 1##set so binary matrix knows where to plot 
h=ax.imshow(highlightc*colour), interpolation='nearest',cmap=plt.cm.spectral_r) 
fig.canvas.draw() 

我想创建一个二进制矩阵,其中情节是不同的颜色。但是目前我遇到了问题,因为它们的阵列形状不一样,所以颜色不会被绘制。我得到错误operands could not be broadcast together with shapes (160,160) (241) 我猜(160 * 160)是矩阵的大小,241是颜色数组的大小。 我有一个坐标数组,我变成了一个二进制数组highlightc。这绘制成功。然而,用颜色我得到了坐标数组的大小,并用它来填充数组来制作颜色。这显然是错误的。基本上我想要的是一定数量是0.21,其余的是1.0。所以,我怎么可以把阵列我有这么它具有形状(160,160)所以它的颜色正确的地块在正确的颜色改变阵列的形状,所以它绘制颜色matplotlib矩阵

+0

如果代码完整,您将有更多机会得到一个很好的答案。即,如果我可以复制粘贴并运行它,而不尝试猜测您的数据和导入语句是什么。如果你不得不输入假的或随机的数据,那很好... – YXD 2013-04-09 10:28:13

回答

1
highlightc = np.ones([N, N]) 
for x, y in hl: 
    highlightc[x, y] = .21 ##set so binary matrix knows where to plot 
h=ax.imshow(highlightc*colour), interpolation='nearest',cmap=plt.cm.spectral_r, vmin=0, mvax=1) 
fig.canvas.draw() 

是你所需要的。

highlgihtc将包含1无处不在,但有几个地方它将是0.21