_main.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:matplotlib_venn_wordcloud 作者: paulbrodersen 项目源码 文件源码
def _get_wordcloud(img, patch, words, word_to_frequency=None, **wordcloud_kwargs):

    # get the boolean mask corresponding to each patch
    path = patch.get_path()
    mask = path.contains_points(img.pixel_coordinates).reshape((img.y_resolution, img.x_resolution))

    # make mask matplotlib-venn compatible
    mask = (~mask * 255).astype(np.uint8) # black indicates mask position
    mask = np.flipud(mask) # origin is in upper left

    # create wordcloud
    wc = WordCloud(mask=mask,
                   background_color=None,
                   mode="RGBA",
                   **wordcloud_kwargs)

    if not word_to_frequency:
        text = " ".join(words)
        wc.generate(text)
    else:
        wc.generate_from_frequencies({word: word_to_frequency[word] for word in words})

    return wc
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号