#!/usr/bin/env python
"""
Minimal Example
===============
Generating a square wordcloud from the US constitution using default arguments.
"""
import os
from os import path
from wordcloud import WordCloud
# using word frequency list:
#word_freq = open("/tmp/word_freq.txt").read()
# say it looks like this:
word_freq = {'apple': 4, 'banana': 1, 'melon': 2, 'strawberry': 3, 'grape': 8}
text = " ".join([(k + " ")*v for k,v in word_freq.items()])
# Generate a word cloud image
wordcloud = WordCloud().generate(text)
# Display the generated image:
# the matplotlib way:
import matplotlib.pyplot as plt
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
# lower max_font_size
wordcloud = WordCloud(max_font_size=40).generate(text)
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()
# The pil way (if you don't have matplotlib)
# image = wordcloud.to_image()
# image.show()
在there之外有很多库。在
下面是一个来自WordCloud的示例
来自不同文本的WordCloud:
让我们来看看频率
下面的代码应该行得通
导入操作系统
相关问题 更多 >
编程相关推荐