Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I save word cloud as .png in python?

Tags:

python

I'm trying to create a word cloud based on a string and then importing it into a report document. I am using python-docx, matplotlib, and word cloud. This is a brief summary of my

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")

However, instead of displaying a word cloud, the report just shows a blank graph.

like image 274
oceandye Avatar asked Sep 23 '18 09:09

oceandye


People also ask

How do I print a word cloud in Python?

The three steps are: Extract the review (text document) Create and generate a wordcloud image. Display the cloud using matplotlib.

How do I export from word cloud?

To export your word cloud, right click or command + click the word cloud and select Export.

What is word cloud package in Python?

Word Cloud is a data visualization technique used for representing text data in which the size of each word indicates its frequency or importance. Significant textual data points can be highlighted using a word cloud. Word clouds are widely used for analyzing data from social network websites.


1 Answers

Supplemental to @Andy's answer, cloud.to_file('N.png') is how you save the word cloud image into your local disk so that you can import later. You can find a good reference here.

like image 98
CathyQian Avatar answered Nov 14 '22 22:11

CathyQian