写了这个简单的小脚本,从今天班加西听证会的记录中创建了一个单词云,但是它被一个我不太明白的错误挂了。
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'
要解决这个问题,改变
到
^{pr2}$我在打字的时候就想好了,但会留下来,因为也许其他人也会有同样的问题。
相关问题 更多 >
编程相关推荐