我正在尝试基于字符串创建词云,然后将其导入到报告文档中。我正在使用 python-docx、matplotlib 和词云。 这是我的简要总结
from wordcloud import WordCloud
import matplotlib.pyplot as plt
from docx import Document
from docx.shared import Inches
document = Document()
document.add_heading("Auto Generated Report")
text = "kd sa gf sdf gd python auomation get set python dfs aslkdf asdfij fdifh fdosfj dsfoj "
cloud = WordCloud().generate(text)
plt.title('Summarization of responses on possible improvements of CS course.')
plt.savefig('N.png')
document.add_picture('N.png', width=Inches(5))
document.save("Report")
但是,该报告没有显示词云,而是显示了一个空白图表。
请您参考如下方法:
作为@Andy 回答的补充,cloud.to_file('N.png') 是将词云图像保存到本地磁盘以便稍后导入的方式。你可以找到一个很好的引用here .
