0
我正尝试使用txt文件中的文本创建wordcloud。来自txt文件的Python Wordcloud
到目前为止,这是我的代码有
import matplotlib.pyplot as plt
from wordcloud import WordCloud, STOPWORDS
file_content=open ("tweets.txt").read()
wordcloud = WordCloud(font_path = 'C:\Windows\Fonts\Verdana.tff',
stopwords=STOPWORDS,
background_color = 'white',
width=1200,
height=1000
).generate(file_content)
plt.imshow(wordcloud)
plt.axis('off')
plt.show()
这是演出结束后我运行这段代码是错误:
File "WordCloud.py", line 14, in <module>
).generate(file_content)
File "C:\Python27\lib\site-packages\wordcloud\wordcloud.py", line 448, in generate
return self.generate_from_text(text)
File "C:\Python27\lib\site-packages\wordcloud\wordcloud.py", line 434, in generate_from_text
self.generate_from_frequencies(words)
File "C:\Python27\lib\site-packages\wordcloud\wordcloud.py", line 317, in generate_from_frequencies
font = ImageFont.truetype(self.font_path, font_size)
File "C:\Python27\lib\site-packages\PIL\ImageFont.py", line 238, in truetype
return FreeTypeFont(font, size, index, encoding)
File "C:\Python27\lib\site-packages\PIL\ImageFont.py", line 127, in __init__
self.font = core.getfont(font, size, index, encoding)
IOError: cannot open resource
奖金的问题:如何改变文字颜色?
给我们一个'tweets.txt'文件的样本。 –
我认为它应该是Verdana.ttf不是.tff – oat
它抱怨缺少字体文件。 '无法打开资源' – oat