python - 如何在 Python 中生成彼此相邻的词云
问题描述
我有以下代码使用 wordclouds 生成 t 图形:
for t in range(n_components):
plt.figure()
plt.imshow(WordCloud().fit_words(lda_top_words[t]))
plt.axis("off")
plt.title("Topic #" + str(t))
plt.show()
我怎样才能改变它来生成一个在同一个图中有多个图的图?
解决方案
我设法使用子图和以下代码解决了我的问题:
def display_wordcloud(top_words, title, n_components):
plt.figure()
j = np.ceil(n_components/4)
for t in range(n_components):
i=t+1
plt.subplot(j, 4, i).set_title("Topic #" + str(t))
plt.plot()
plt.imshow(WordCloud().fit_words(top_words[t]))
plt.axis("off")
fig.suptitle(title)
plt.show()
这里的 n_components 是我想看到的图的数量,也是我的主题模型中不同主题的数量。Top_words 是我的主题模型中每个主题的热门词,而 tile 是我想要的人物的标题
此代码每行显示 4 个图。
推荐阅读
- jquery - jQuery — 从文本字符串中去除 URL
- python - 动态 mySQL 语句
- r - 使用 lag() 和 mutate() 在嵌套的 tibble 中加入当前和以前的数据帧以生成新的列表列
- google-analytics - Google Analytics(分析)归因模型中转化价值较低的首次互动
- salesforce - LWC SuperBadge - 步骤 14
- tiddlywiki - 如何更改标签选择弹出窗口的行为?
- assembly - Clang Assembler 中的以下内容是什么意思
- api - 用于添加志愿者体验的 addtoprofile url
- c++ - 循环不循环的猜谜游戏
- php - WordPress 如何在安装自定义 WordPress 主题时以编程方式自动生成页面并将它们分配给博客页面和首页