When the list cannot meet the needs of people to present information, the label cloud display method can well meet the browsing needs of people who pay attention to key points, highlight trends, and display preferences, this article briefly introduces how to use python to generate a tag cloud.
There are two methods:
1. Self-implementation (you can refer to the http://www.i-alive.com/post/11)
2. Use existing libraries, mainly pytagcloud
This article mainly uses the pytagcloud library to generate the tag cloud. Install Python first. However, if Python game and simplejson are not installed on your machine, download and install Python first.
These three packages are easy to use after they are installed.CodeAs follows:
1 From Pytagcloud Import Create_tag_image, make_tags 2 From Pytagcloud. Lang. Counter Import Get_tag_counts 3 4 TEXT = ''' 5 Python (2) compiler (1) OLAP (1) 6 Recommender-system (2) crawler (1) Python networkx (1 )) 7 Sinaweio (1) dremel (1) Python-multi-thread (1) path (1) 8 Mobile-internet (1) hadoop hbase HDFS zookeeper (1) meachine-learning (1) 9 Similarity (1) hbase zookeeper (1) opensource (1) 10 Python (2) Python-multi-thread (1) mahout itembased-CF (1) 11 Levenshtein (1) 12 Auto-check (1) mahout itembased (1) Real-time Data Analysis 13 Python (2) recommender-system (2) Python recommender-system (1) Real (1) 14 Mapreduce shuffle (1) Video (1) 15 Ant (1) Native hadoop libraries (1) Search (1) 16 Bigtable (1) NC (1) 17 Recommender-system (1) bigdata (1) data-analysis (1) 18 ''' 19 Tags = make_tags (get_tag_counts (text), maxsize = 150 ) 20 Create_tag_image (tags, ' Cloud_large.png ' , Size = (900,600 ))
A result file cloud_large.png will be generated in the current directory after running. The result is as follows:
In addition to generating images, pytagcloud can also generate HTML-based tag clouds for interaction with users. For more information, see the pytagcloud documentation.