python生成词云报错:ValueError: anchor not supported for multiline text
执行下面代码时报错:
# 生成词云对象 wordcloud = WordCloud(font_path="E:\\data\\python\\simhei.ttf" ,background_color="white" ,max_font_size=80) #前1000个词 word_frequence={x[0]:x[1] for x in words_stat.head(1000).values} word_frequence #生成词云 wordcloud = wordcloud.fit_words(word_frequence) plt.imshow(wordcloud)
报错信息:ValueError: anchor not supported for multiline text
定位到是调用下面语句时报错:
wordcloud = wordcloud.fit_words(word_frequence)
网上查了一圈,发现是如果,数据中有\n则会报错
将数据中的 '\n' 行删除后问题解决