Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Python generates Chinese word cloud

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Beans inadvertently found that Python has a ready-made module word cloud can generate word clouds based on text files, very good and powerful, a simple game.

Before you can write code, you first need to install three dependent Python modules, namely matplotlib, jieba, and wordcloud. These three modules are used for drawing, Chinese word segmentation and word cloud generation respectively. The installation method can be implemented directly through pip install. If there is an error in the online installation (most likely), you can go to https://www.lfd.uci.edu/~gohlke/pythonlibs/ to download the corresponding version and number of whl files, and then you can still specify the downloaded file installation through pip install.

Here's a simple example:

First of all, download a background picture for my word cloud, and the pattern and even color generated at that time will be the same as this. I casually downloaded a picture of a bear.

Then casually downloaded a piece of news from Sina and saved it as a txt file.

Beijing, 31 Jan (Xinhua)-- the political Bureau of the CPC Central Committee held its third collective study on building a modern economic system on the afternoon of 30 January. When presiding over the study, General Secretary of the CPC Central Committee stressed that building a modern economic system is a major article, which is not only a major theoretical proposition, but also a major practical topic, which needs to be discussed in depth from the combination of theory and practice. The construction of a modern economic system is not only the strategic goal of China's development, but also the urgent requirement of changing the mode of economic development, optimizing the economic structure and transforming the driving force of economic growth. The whole party must deeply understand the importance and arduousness of building a modern economic system, scientifically grasp the goals and key points of building a modern economic system, and promote China's economic development to coruscate new vitality and reach a new level. During the collective study of the political Bureau of the CPC Central Committee, comrades of the political Bureau of the CPC Central Committee studied by themselves and exchanged experiences. Liu he, Sun Chunlan, Li Xi, Li Qiang, Li Hongzhong, Chen Guoguo, Chen Miner, × ×, and Cai Qi made key speeches on this issue. comrades of the political Bureau of the CPC Central Committee listened to their speeches and discussed relevant issues. Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx made a speech when presiding over the study. He pointed out that building a modern economic system is a major policy decision made by the CPC Central Committee in the light of the overall situation of the cause of the party and the state, with a view to achieving the "two centenary" goals and conforming to the new requirements of socialism with Chinese characteristics entering a new era. If the country is strong, the economic system must be strong. Only by forming a modern economic system can we better comply with the development trend of modernization and win the initiative of international competition, and provide strong support for modernization in other fields. In accordance with the requirements of building a modern socialist power, we should speed up the construction of a modern economic system and ensure that the goal of a modern socialist power is realized as scheduled. It is emphasized that the modern economic system is an organic whole composed of the interrelations and internal relations of all links, levels, and fields of social and economic activities. It is necessary to build an industrial system led by innovation and coordinated development, realize the coordinated development of real economy, scientific and technological innovation, modern finance and human resources, and continuously increase the contribution share of scientific and technological innovation in the development of real economy. the ability of modern financial services to the real economy is constantly enhanced, and the role of human resources in supporting the development of the real economy is constantly optimized. It is necessary to build a unified, open and orderly market system to achieve smooth market access, open and orderly market, full market competition, and standardized market order. we will speed up the formation of a modern market system in which enterprises operate independently and compete fairly, consumers choose freely and consume independently, and goods and elements are freely flowed and exchanged equally. It is necessary to build an income distribution system that embodies efficiency and promotes fairness, achieve reasonable income distribution, social fairness and justice, and the common prosperity of all the people, promote the equalization of basic public services, and gradually narrow the income distribution gap. It is necessary to build a regional development system of urban and rural areas that demonstrates advantages and coordinated linkage, realizes benign regional interaction, integrated development of urban and rural areas, and overall optimization of land and sea, cultivates and gives full play to regional comparative advantages, and strengthens the complementarity of regional advantages. we will shape a new pattern of regional coordinated development. To build a resource-saving and environment-friendly green development system, to achieve green cycle and low-carbon development, harmonious symbiosis between man and nature, firmly establish and practice the concept of green water and green mountains is Jinshan and Silver Mountain, and form a new pattern of harmonious development and modernization between man and nature. It is necessary to build a pluralistic and balanced, safe and efficient comprehensive opening-up system, develop an open economy at a higher level, and promote the transformation of opening up in the direction of optimizing structure, expanding depth, and improving efficiency. It is necessary to build an economic system that gives full play to the role of the market and the government, so as to achieve an effective market mechanism, a dynamic micro-body, and a degree of macro-control. The above systems are a unified whole, which should be built and promoted as a whole. The modern economic system we are building should learn from the useful practices of developed countries, and should be more in line with China's national conditions and with Chinese characteristics. It is pointed out that the construction of a modern economic system requires solid and effective policy measures and actions. It is necessary to highlight and do a good job in the following aspects. First, it is necessary to vigorously develop the real economy and build a solid foundation for a modern economic system. The real economy is the foundation of a country's economy, the fundamental source of wealth creation and an important pillar of national prosperity. It is necessary to deepen supply-side structural reform, speed up the development of advanced manufacturing industries, and promote the deep integration of the Internet, big data, and artificial intelligence with the real economy. we will promote the agglomeration of resource elements to the real economy, tilt policies and measures towards the real economy, and strengthen the working force to the real economy, so as to create a development environment and social atmosphere for down-to-earth, industrious entrepreneurship and industrial prosperity. Second, it is necessary to speed up the implementation of the innovation-driven development strategy, strengthen the strategic support of the modern economic system, strengthen the construction of the national innovation system, strengthen the strategic scientific and technological strength, and promote the deep integration of scientific and technological innovation and economic and social development. to shape more leading development that is driven by innovation and gives full play to its first-mover advantages. Third, we should actively promote the coordinated development of urban and rural areas, optimize the spatial layout of the modern economic system, implement the strategy of coordinated regional development, promote the coordinated development of Beijing, Tianjin and Hebei and the development of the Yangtze River Economic Belt, and at the same time coordinate the development of Guangdong-Hong Kong-Macau Greater Bay Area. The revitalization of the countryside is a big game of chess, and we should do it well. Fourth, we should focus on developing an open economy, enhance the international competitiveness of the modern economic system, make better use of global resources and markets, and continue to actively promote international exchanges and cooperation under the framework of "Belt and Road Initiative." Fifth, it is necessary to deepen the reform of the economic system, improve the institutional guarantee of the modern economic system, speed up the improvement of the socialist market economic system, resolutely eliminate the shortcomings of various systems and mechanisms, and stimulate the innovative and entrepreneurial vitality of the whole society. (end) responsible Editor: Zhang Jianli

Python code

From os import pathfrom PIL import Imageimport numpy as npimport matplotlib.pyplot as pltfrom wordcloud import WordCloud, STOPWORDS, ImageColorGeneratord = path.dirname (_ _ file__) # Read the whole text.text = open (path.join (d, 'xidada.txt'), encoding='utf-8'). Read () import jieba# stuttering participle wordlist = jieba.cut (text, cut_all=True) wl = ".join (wordlist) print (wl) # txtcoloring = np.array (path.join (d) # output participle ("bear.jpg") # set the disabled word # stopwords = set (STOPWORDS) # stopwords.add ("said") # you can set the cloud shape wc = WordCloud (background_color= "white", max_words=2000, mask=coloring, max_font_size=50, random_state=42,font_path='fangsong_GB2312.ttf') wc.generate (wl) # create coloring from imageimage_colors = ImageColorGenerator (coloring) # show# if only mask is set You will get a word cloud plt.imshow (wc, interpolation= "bilinear") plt.axis ("off") plt.figure () plt.show () with a picture shape.

Effect picture

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report