I am trying to generate a svg of the word_cloud being formed out of some hardcoded strings(as of now, later these strings will be dynamically generated). Below is the Python code to generate word_cloud:
from os import path
from wordcloud import WordCloud
d = path.dirname(__file__)
# Read the whole text.
#text = open(path.join(d, 'test.txt')).read()
mytext = ['hello, hi, ibm, pune, hola']
# Generate a word cloud image
wordcloud = WordCloud().generate(text)
import svgwrite
# Display the generated image:
# the matplotlib way:
import matplotlib.pyplot as plt
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
Now instead of using plt.show(), I want to pass the wordcloud variable to svgwrite method as below:
svg_document = svgwrite.Drawing(filename = "test-svgwrite.svg",profile = 'full')
svg_document.add(svg_document.text(wordcloud,
insert = (210, 110)))
svg_document.tostring()
svg_document.save()
However, this created SVG doesn't contain any wordcloud, only the text (shown in below screenshot): check the screenshot here
Facing some issues using matplotlib (which will use raster graphics in combination with wordcloud although it will be saved as ".svg"), i have figured out another way
The embed_font boolean prevented the words from overlapping. Also you have a lot of freedom modifying wordcloud_svg to change colors, fonts , etc. It has an xml-like structure (print it :) )