我通过wordcloud来制作词云,过程顺利只是最后生成的图片出现了多次关键字重复:
关键的代码如下:
wcd=WordCloud(font_path='simsun.ttc',width=900,height=400,background_color='white',max_words=100,scale=1.5).generate(text)
其中text是一堆词语,print出来的一部分为:
如何解决呢?
我通过wordcloud来制作词云,过程顺利只是最后生成的图片出现了多次关键字重复:
关键的代码如下:
wcd=WordCloud(font_path='simsun.ttc',width=900,height=400,background_color='white',max_words=100,scale=1.5).generate(text)
其中text是一堆词语,print出来的一部分为:
如何解决呢?
用jieba.analyse分出词频,然后用generate_from_frequencies(keywords)
示例如下:
result=jieba.analyse.textrank(text_from_file_with_apath,topK=300,withWeight=True)
keywords = dict()
for i in result:
keywords[i[0]]=i[1]
wc = WordCloud(stopwords=stopwords, font_path=font, width = 1600, height = 900, margin=10, max_font_size = 360, min_font_size = 36, background_color="black", mask=mask).generate_from_frequencies(keywords)
2 回答5.1k 阅读✓ 已解决
2 回答1.1k 阅读✓ 已解决
4 回答1k 阅读✓ 已解决
3 回答1.1k 阅读✓ 已解决
3 回答1.2k 阅读✓ 已解决
1 回答1.7k 阅读✓ 已解决
1 回答1.2k 阅读✓ 已解决
与collocations参数有关,默认collocations=True,会统计搭配词。比如你的text是“我在拜访客户”,当collocations为True时,就会把“拜访客户”也当作一个词进行统计,所以会出现重复。
wcd=WordCloud(font_path='simsun.ttc', collocations=False,width=900,height=400,background_color='white',max_words=100,scale=1.5).generate(text)