python - change shape of array so it plots colour matplotlib matrix -
this question has answer here:
- colour binary matrix matplotlib 1 answer
hl = [(1,109),(12,212),(21,23)] highlightc = np.zeros([n, n]) c = len(highlightc) colour = [0.21]*c test = len(number_list) -c = [0.21]*test colour.extend(this) colour = np.array(colour) colour = np.array(colour) print len(number_list) print colour x, y in hl: highlightc[x, y] = 1##set binary matrix knows plot h=ax.imshow(highlightc*colour), interpolation='nearest',cmap=plt.cm.spectral_r) fig.canvas.draw()
i trying create binary matrix, plots different colours. @ moment have problem arrays not same shape, colour not plotted. error operands not broadcast shapes (160,160) (241)
i'm guessing (160*160) size of matrix , 241 size of colour array. have array of coordinates turned binary array highlightc
. plots successfully. colour got size of coordinate array, , used populate array make colours. wrong. want amount 0.21
, rest 1.0
. how can turn array have got has shape (160,160)
colours correct plots in correct color
highlightc = np.ones([n, n]) x, y in hl: highlightc[x, y] = .21 ##set binary matrix knows plot h=ax.imshow(highlightc*colour), interpolation='nearest',cmap=plt.cm.spectral_r, vmin=0, mvax=1) fig.canvas.draw()
is need.
highlgihtc
contain 1
everywhere few places 0.21
.
Comments
Post a Comment