Word cloud (tag cloud or wordle) is a novelty visual representation of text data. The importance of each word is shown with its font size, position, or color. WordCloud.jl
is an ideal tool in the Julia language for creating word clouds, offering several key benefits:
- Flexible - You have control over every aspect of generating a word cloud. You can customize the shape, color, angle, position, distribution, density, and spacing to align with your preferences and artistic style.
- Faithful - This visualization solution guarantees precise results. Each word appears only once, and its font size is determined solely by the provided weight. Words are never repeated or shrunk artificially to fill empty spaces.
- Efficient - It utilizes intelligent strategies and efficient nesting algorithms, implemented entirely in Julia (see Stuffing.jl). As a result, it can easily generate high-resolution word clouds.
🌐 Try the online generator 🌐 (a bit slow)
import Pkg; Pkg.add("WordCloud")
using WordCloud
using Random
words = [randstring(rand(1:8)) for i in 1:300]
weights = randexp(length(words))
wc = wordcloud(words, weights)
generate!(wc)
paint(wc, "random.svg")
Other input types are also supported:
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(["中文", "需要", "提前", "分词"]) |> generate! # from a list
wc = wordcloud(["the"=>1.0, "to"=>0.51, "and"=>0.50]) |> generate! # from pairs or a dict
And you can get the word cloud picture in one step:
paintcloud("obtain the final picture directly")
using WordCloud
textfile = pkgdir(WordCloud)*"/res/alice.txt"
maskfile = pkgdir(WordCloud)*"/res/alice_mask.png"
wc = wordcloud(
open(textfile),
stopwords_extra = ["said"],
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")
try runexample(:alice)
or showexample(:alice)
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.
WordCloud.jl stands out from other tools due to its unique approach based on image local gradient optimization. Unlike conventional algorithms, WordCloud.jl utilizes a non-greedy algorithm that enables words to be repositioned even after their initial placement. This dynamic adjustment process provides unparalleled freedom in assigning words to any desired position, irrespective of potential overlaps. Furthermore, it eliminates the necessity of scaling words during the adjustment phase. This ingenious design choice maximizes the generator's flexibility, opening up boundless possibilities for customization. For a more detailed understanding of the algorithm, you can refer to the Stuffing.jl - Algorithm Description.
- 权重计算和单词位置初始化
- 基于四叉树(层次包围盒)的碰撞检测
- 根据局部灰度梯度平移单词(训练迭代)
- 引入动量加速训练
- 分代检测优化性能(for pairwise trainer)
- 区域四叉树批量碰撞检测
- LRU优化性能(for element-wise trainer)
- 控制字体大小和填充密度的策略
- 使用重新放置策略跳出局部最优
- 使用缩放策略降低训练难度
- 训练失败检测和提前中断
- 主题配色等
- 并行计算