wordcloud解决‘'list' object has no attribute 'items'
from os import path from wordcloud import WordCloud from matplotlib import pyplot as plt # 定义为列表会报错 frequencies = [(u'知乎',5),(u'小段同学',4),(u'曲小花',3),(u'中文分词',2),(u'样例',1)] #修改为字典格式就ok了 frequencies1 = dict(frequencies) # 直接传列表会报错,转入转换之后的格式就好了 wordcloud = WordCloud(max_font_size=40, relative_scaling=.5).fit_words(frequencies1) plt.figure() plt.imshow(wordcloud) plt.axis("off") plt.show()
本文来自博客园,作者:沉迷编程的程序员,转载请注明原文链接:https://www.cnblogs.com/codeDevotee/p/12188161.html
欢迎各位找我代写程序,python、c#、web等都可以,加我请注明博客园微信:A15919195482