current position:Home>Python drawing word cloud
Python drawing word cloud
2022-05-15 02:53:57【Torres saint】
wordcloud:
- Install the module :
pip install wordcloud
- Basic use :
WordCloud(font_path, background_color, width, height, max_words).generate(xxx)
font_path
: The font of the textcollocations
: Whether it contains the collocation of two words , The default is true, So there will be duplicate databackground_color
: Background colorwidth
: The width of the curtainheight
: Height of curtainmax_words
: Maximum number of words displayedgenerate
: Read text file
- Case study :
from wordcloud import WordCloud
with open("xxx.txt", encoding="utf-8") as r:
# Read the text
txt = r.read()
# Set the style of word cloud
wordcloud = WordCloud(font_path="xxx.ttf", collocations=False, background_color="black", width=800, height=600, max_words=50).generate(txt)
# Generate pictures
img = wordcloud.to_image()
# Show pictures
img.show()
# Save the picture
wordcloud.to_file("xxx.jpg")
jieba:
- Install the module :
pip install jieba
- The basic format :
jieba.analyse.extract_tags(xxx, topK, withWeight, allowPOS)
xxx
: Text to be processedtopK
: Returns the number of keywords , Importance goes from high to lowwithWeight
: Returns the weight of each keywordallowPOS
: The part of speech to be extracted ,n Is a noun 、v It's a verb , The value passed is Yuanzu
- Case study :
import jieba.analyse
from wordcloud import WordCloud
# Set text content
text = ""
# Use jieba participle , Extract key words
seg_list = jieba.analyse.extract_tags(text, allowPOS=("n", "v"))
# Splice keywords into strings
txt_str = " ".join(seg_list)
# Set the style of word cloud
wordcloud = WordCloud(font_path="xxx.ttf", collocations=False, background_color="black", width=800, height=600, max_words=50).generate(txt_str)
# Generate pictures
img = wordcloud.to_image()
# Show pictures
img.show()
# Save the picture
wordcloud.to_file("xxx.jpg")
copyright notice
author[Torres saint],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/132/202205120036302156.html
The sidebar is recommended
- Common modules and third-party libraries of Python notes in class
- Educoder Linux and Python Programming 2021 (basic syntax of classes) - level 2: properties and instantiation of classes
- Educoder Linux and Python Programming 2021 (basic syntax of classes) - level 1: Declaration and definition of classes
- Educoder Linux and Python Programming 2021 (basic syntax of classes) - Level 3: binding and method calling
- Educoder Linux and Python Programming 2021 (basic syntax of classes) - level 4: static methods and class methods
- Educoder Linux and Python Programming 2021 (basic syntax of classes) - level 5: class import
- Python: unable to connect because the target computer actively refused
- If I can only choose one of the python introductory books on the market for you, I will choose this one
- Python simulation | how to manipulate the winning or losing of football matches
- How to learn after joining our Python zero foundation learning group?
guess what you like
Why choose Python as a programming language
Functions in Python
Python version of the lone brave | drawing + playing + Music Visualization
Smplify -python2. seven
Python office automation: use Python to automatically insert signatures into docx files
Python uses the opencv method to automatically insert the signed image into any position of the image
Python automatically inserts signatures into PDF files (pypdf2)
Basic learning notes of Python
Numpy, pandas, Matplotlib learning
[brush question Python] the problem of cutting and selling pipes to maximize profits
Random recommended
- [Python] gradient descent method to solve the trough of univariate quadratic function
- Python regular expression
- [Python GUI] wxPython automated data generator practice
- Python script compilation process
- [Python faiss library] (I) Introduction
- Python moves (copies) the pictures (files) under one file to another folder
- Python crawling 51job position information (regular violence matching)
- Python Post Bar irrigation script
- Python simulation QR code login Baidu
- Python calls wechat to send message call through COM port
- Analysis of birthday paradox in Python
- Equal scale compression of image files in Python
- Python dynamic programming (knapsack problem and longest common substring)
- Introduction to Python Programming and data analysis (I) basic use of built-in functions
- Introduction to Python Programming and data analysis (II) basic use of list derivation
- Introduction to Python Programming and data analysis (III) basic use of branch and process control
- Python turtle painting Chinese characters
- [a quick introduction and comparison of multiple languages -- JavaScript, typescript, python, golang, trust, Java, ruby]
- Relevant knowledge of Python web development (I)
- python3. Understanding of ID function in 6
- JSON data storage of MySQL in Python
- Python 3 development function
- My pandas
- Python game programming (pyGame)
- Python word cloud
- Python crawler crawls the Douban movie ranking list and writes it into CSV file for visual data analysis
- Python crawler crawls Beijing Xinfadi vegetables and displays them visually
- Python climbed the world university rankings
- Python crawling material commune picture
- Exception handling in Python and explanation of OS module
- Summation of corresponding position elements of multiple lists in Python
- [Python pandas] read excel table contents
- Python zip() function usage
- Application of Python startup subclass subprocess class
- Python's logging module
- MySQL application of Python
- Interesting games designed in Python
- Regularity of Python
- Jenkins reported an error in building Python project: CX_ Oracle. DatabaseError: DPI-1047: oci. dll is not the correct architecture
- Hamcrest assertion Library of Python