97 Stars
Updated Last
1 Year Ago
Started In
September 2019

Dev Binder CI CI-nightly codecov DOI
Word cloud (tag cloud or wordle) is a novelty visual representation of text data. The importance of each word is shown with font size or color. Our generator has the following highlights:

  • Flexible - any shape, any color, any angle, adjustable density and spacing. The initial position of words can be set at will. And words can be pinned during fitting.
  • Exact - not only artistic but also rigorous. Words with the same weight have the exact same size and will never be scaled or repeated to fill in blanks.
  • Efficient - smart strategy and efficient nesting algorithm, 100% in Julia (see Stuffing.jl). Easily generate high resolution results.

🌐 Try the online generator 🌐

Go to the gallery


import Pkg; Pkg.add("WordCloud")

Basic Usage

using WordCloud
using Random
words = [randstring(rand(1:8)) for i in 1:300]
weights = randexp(length(words))
wc = wordcloud(words, weights)
paint(wc, "random.svg")

Alternatively, it could be

wc = wordcloud("It's easy to generate word clouds") |> generate! #from a string
wc = wordcloud(open(pkgdir(WordCloud)*"/res/alice.txt")) |> generate! #from a file
wc = wordcloud(["中文", "需要", "提前", "分词"], fonts="") |> generate! #from a list
wc = wordcloud(["the"=>1.0, "to"=>0.51, "and"=>0.50,
                  "of"=>0.47, "a"=>0.44, "in"=>0.33]) |> generate! #from pairs or a dict

Advanced Usage

using WordCloud
stopwords = WordCloud.stopwords_en  ["said"]
textfile = pkgdir(WordCloud)*"/res/alice.txt"
maskfile = pkgdir(WordCloud)*"/res/alice_mask.png"
wc = wordcloud(
    processtext(open(textfile), stopwords=stopwords, maxnum=500), 
    mask = maskfile,
    maskcolor = "#faeef8",
    outline = 4,
    linecolor = "purple",
    colors = :Set1_5,
    angles = (0, 90),
    fonts = "Tahoma",
    density = 0.55,
    spacing = 3,) |> generate!
paint(wc, "alice.png", ratio=0.5)

try runexample(:alice) or showexample(:alice)

More Examples

Gathering style

try runexample(:gathering) or showexample(:gathering)


try runexample(:recolor) or showexample(:recolor)


try runexample(:semantic) or showexample(:semantic)
The variable WordCloud.examples holds all available examples.

About Implementation

Unlike most other implementations, WordCloud.jl is programmed based on image local gradient optimization. It’s a non-greedy algorithm in which words can be further moved after they are positioned. This means shrinking words is unnecessary, thus the word size can be kept unchanged during the adjustment. In addition, it allows words to be assigned to any initial position whether or not there will be an overlap. This enables the program to achieve the maximum flexibility. See also Stuffing.jl - Algorithm Description.

  • 权重计算和单词位置初始化
  • 基于四叉树(层次包围盒)的碰撞检测
  • 根据局部灰度梯度平移单词(训练迭代)
  • 引入动量加速训练
  • 分代检测优化性能(for pairwise trainer)
  • 区域四叉树批量碰撞检测
  • LRU优化性能(for element-wise trainer)
  • 控制字体大小和填充密度的策略
  • 使用重新放置策略跳出局部最优
  • 使用缩放策略降低训练难度
  • 训练失败检测和提前中断
  • 主题配色等
  • 并行计算



mv wqy-microhei.ttc ~/.fonts
fc-cache -vf


add /path/to/ffmpeg-4.2.1/lib to ENV["LD_LIBRARY_PATH"]
add /path/to/ffmpeg-4.2.1/bin to ENV["PATH"]

External Links

Used By Packages

No packages found.