WordCloud模块类型有点问题错误:yu init_Uu()获得了意外的关键字参数“relative_scaling”

2024-04-24 07:04:03 发布

您现在位置:Python中文网/ 问答频道 /正文

写了这个简单的小脚本,从今天班加西听证会的记录中创建了一个单词云,但是它被一个我不太明白的错误挂了。

from os import path
from wordcloud import WordCloud

d = path.dirname(__file__)

# Read the whole text.
text = open(path.join(d, 'clintonSpeech.txt')).read()

# Generate a word cloud image
wordcloud = WordCloud().generate(text)

# Display the generated image:
# the matplotlib way:
import matplotlib.pyplot as plt
plt.imshow(wordcloud)
plt.axis("off")

# take relative word frequencies into account, lower max_font_size
wordcloud = WordCloud(max_font_size=40, relative_scaling=.5).generate(text)
plt.figure()
plt.imshow(wordcloud)
plt.axis("off")
plt.show()

回溯: Traceback (most recent call last): File "wordCloud.py", line 19, in <module> wordcloud = WordCloud(max_font_size=40, relative_scaling=.5).generate(text) TypeError: __init__() got an unexpected keyword argument 'relative_scaling'


Tags: thepathtextfromimportsizepltmax