def vis_att(pages_idx, query, alpha, wiki, vocab, idx):
rows = [prm.root_page.title()]
for pageidx in pages_idx[:-1]:
if pageidx != -1:
rows.append(wiki.get_article_title(pageidx).decode('utf-8', 'ignore').title())
else:
break
#rows.append('Stop')
rows = rows[::-1]
columns = []
for word in wordpunct_tokenize(query):
if word.lower() in vocab:
columns.append(str(word))
columns = columns[:prm.max_words_query*prm.n_consec]
alpha = alpha[:len(rows),:len(columns)]
alpha = alpha[::-1]
fig,ax=plt.subplots(figsize=(27,10))
#Advance color controls
norm = matplotlib.colors.Normalize(0,1)
im = ax.pcolor(alpha,cmap=plt.cm.gray,edgecolors='w',norm=norm)
fig.colorbar(im)
ax.set_xticks(np.arange(0,len(columns))+0.5)
ax.set_yticks(np.arange(0,len(rows))+0.5)
ax.tick_params(axis='x', which='minor', pad=15)
# Here we position the tick labels for x and y axis
ax.xaxis.tick_bottom()
ax.yaxis.tick_left()
ax.axis('tight') # correcting pyplot bug that add extra white columns.
plt.xticks(rotation=90)
fig.subplots_adjust(bottom=0.2)
fig.subplots_adjust(left=0.2)
#Values against each labels
ax.set_xticklabels(columns,minor=False,fontsize=18)
ax.set_yticklabels(rows,minor=False,fontsize=18)
plt.savefig('vis' + str(idx) + '.svg')
plt.close()
评论列表
文章目录