【问题标题】:How to generate wordclouds next to each other in Python如何在 Python 中生成彼此相邻的词云
【发布时间】:2019-06-02 06:04:31
【问题描述】:

我有以下代码可以用 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()

如何更改此设置以生成一个图形,在同一个图形中包含多个图?

【问题讨论】:

标签: python matplotlib plot word-cloud


【解决方案1】:

我设法使用子图和以下代码解决了我的问题:

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 个图。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-22
    • 2017-12-26
    • 2018-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多