Python production Tag Cloud

Source: Internet
Author: User

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-implemented

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. The example code is as 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 sinaWeibo O (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 bytes after runtime, a result file cloud_large.png is generated in the current directory. 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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.