내 연락처 정보
우편메소피아@프로톤메일.com
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()
알아채다:
한자가 깨져 있는 경우 다음과 같은 방법으로 수정할 수 있습니다.
글꼴 추가
wordcloud = WordCloud(width=800, height=400, background_color='white', font_path='simhei.ttf').generate(text)
수정 후 효과:
상해
설치 라이브러리:
Word 파일의 내용을 읽으십시오.
단어 클라우드 다이어그램 생성:
지침
위의 단계를 통해 Word 파일을 쉽게 읽고 아름다운 단어 클라우드 다이어그램을 생성할 수 있습니다.