打开IDLE,新建文件singleWord.py
import numpy as np
import matplotlib.pyplot as plt
from wordcloud import WordCloud
text = "Love"
x, y = np.ogrid[:300, :300]
mask = (x - 150) ** 2 + (y - 150) ** 2 > 130 ** 2
mask = 255 * mask.astype(int)
wc = WordCloud(background_color="white", repeat=True, mask=mask)
wc.generate(text)
plt.axis("off")
plt.imshow(wc, interpolation="bilinear")
plt.show()
保存并运行,要修改单词,只需要将text = "Love"改为其它单词。