2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
pip install python-docx wordcloud matplotlib
import docx
from wordcloud import WordCloud
import matplotlib.pyplot as plt
# 读取Word文件内容
def read_word_file(file_path):
doc = docx.Document(file_path)
full_text = []
for para in doc.paragraphs:
full_text.append(para.text)
return 'n'.join(full_text)
# 生成词云图
def generate_wordcloud(text):
wordcloud = WordCloud(width=800, height=400, background_color='white').generate(text)
# 显示词云图
plt.figure(figsize=(10, 5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.show()
# 主函数
def main():
file_path = 'your_word_file.docx' # 替换为你的Word文件路径
text = read_word_file(file_path)
generate_wordcloud(text)
if __name__ == "__main__":
main()
Animadverte:
Si characteribus Sinensibus interpolatae sunt, eas his modis mutare potes:
Add font
wordcloud = WordCloud(width=800, height=400, background_color='white', font_path='simhei.ttf').generate(text)
Effectus post modificationem;
Explicatio
Bibliotheca instruitur:
Legere contentum Verbi file:
Verbum generate nubes tabula:
Cautiones
Per gradus superiores, facile potes legere Verbum lima et pulchra verba nubes diagram generare.