'How to generate a picture with high resolution using Python and word cloud

I am just studying Python and word cloud. But my picture is with low resolution. For example, the sample data is:

import os
import math
from PIL import Image
from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator, get_single_color_func
a3='Python Python Python Matplotlib Matplotlib Seaborn Network Plot Violin Chart Pandas Datascience Wordcloud Spider Radar Parrallel Alpha Color Brewer Density Scatter Barplot Barplot Boxplot Violinplot Treemap Stacked Area Chart Chart Visualization Dataviz Donut Pie Time-Series Wordcloud Wordcloud Sankey Bubble'

and my code is:

building = np.array(Image.open("C://******/house.png"))
wordcloud = WordCloud(background_color="GhostWhite",width=800, height=800, margin=2,collocations=False,
                  mask=building,font_step=2).generate(a3)
plt.figure(figsize=(10,7), facecolor='k')
plt.imshow(wordcloud)
plt.axis("off")
plt.tight_layout(pad=0)
plt.show()

Here is the house picture I use in my code:

enter image description here

Then, here is my result:

enter image description here

You can see the resolution is pretty low. Actually, this is just a small sample data. When I use my real data, I have a picture that is much worse than this.

How can I improve the resolution?



Solution 1:[1]

According to my observation, you have to increase width=800, height=800

and plt.figure(figsize = (16,9)) for 2k resolution or you can increase it.

Solution 2:[2]

You can use the method to_svg and get a resolution however high you want.

    with open("Output.svg", "w") as text_file:
    text_file.write(wc.to_svg())

Try an example by appending these two lines to this file, and the result is gorgeous.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rudra Mohan
Solution 2 Zack Light