PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, May 6, 2022

[FIXED] How to generate a picture with high resolution using Python and word cloud

 May 06, 2022     image, python, resolution, word-cloud     No comments   

Issue

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

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.



Answered By - Rudra Mohan
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing