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()