[ANN] WordCloud.jl - a word cloud generator in julia

Hi, I’m very happy to announce my first julia package WordCloud.jl here. 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. WordCloud.jl has the following highlights:

  • Flexible Any mask, any color, any angle, adjustable filling rate. You can specify the initial position of some words. Or you can pin some words and adjust others, etc.
  • Fast 100% in Julia and efficient implementation based on Quadtree & gradient optimization. The advantage is more obvious when generating large images.
  • Exact Words with the same weight have the exact same size. The algorithm will never scale the word to fit the blank.

A example

using WordCloud
wc = wordcloud(
    process(open(pkgdir(WordCloud)*"/res/alice.txt"), stopwords=WordCloud.stopwords_en ∪ ["said"]), 
    mask = loadmask(pkgdir(WordCloud)*"/res/alice_mask.png", color="#faeef8"),
    colors = :Set1_5,
    angles = (0, 90),
    fillingrate = 0.7) |> generate!
paint(wc, "alice.png", ratio=0.5, background=outline(wc.mask, color="purple", linewidth=1))

alice

You can install WordCloud.jl with command import Pkg; Pkg.add("WordCloud"), and see showexample and runexample for more examples.

I am looking forward to your valuable suggestions. Thank you.

75 Likes

Beautiful

guxiang
Aha, I can reply to bypass the limit of one image.

3 Likes

3 Likes

Really cool! :tada: The fact that it is 100% Julia is awesome :julia: :wink:

8 Likes

Is there a way to export SVGs, ideally with clickable links?

3 Likes

Not yet, but relevant information can be obtained through getposition(wc), getangle(wc), getweight(wc) and getword(wc) :slightly_smiling_face:

4 Likes

Haha what a nice coincidence! I was just looking for a tool to make a word cloud for a presentation I will give in two weeks, and this is a nice timely surprise!

3 Likes

Ha ha, I hope it can help you :laughing:

2 Likes

SVG exporting is supported at v0.4.0:v: You just need to paint(wc, "filename.svg") or paintsvg(wc). While, this feature depends on Luxor v2.8.0 which may be released after Julia 1.6. Therefore, it’s not currently available via Pkg’s update.

8 Likes

https://github.com/JuliaGraphics/Luxor.jl/issues/140

1 Like

I’m looking forward to it. Thank you for your great work.

1 Like

Very good stuff. Would it be possible for someone to generate a word cloud for the Julia discourse repository?

1 Like

We need .txt or .html files as inputs. Running showexample(:juliadoc) in v0.4.0 can show the way to generate word cloud from julia’s html docs. Moreover, showexample(:fromweb) shows a example that generates a word cloud from online web page.

1 Like

Awesome Julia! I think this generator is more powerful than many other popular generators in other language ecosystems. Isn’t it?

1 Like

I have been using it and the functionality is great, wish there were some docs for it though as it appears there are quite a few options to choose from.

@guoyongzhi Thanks for the library, been using it and it is great! For the example in GitHub - guo-yong-zhi/WordCloud-Gallery: A Gallery for WordCloud.jl I get an error ```UndefVarError: randommaskcolor not defined

I updated the gallery before the releasing of the new version of the WordCloud.jl itself, which led to some inconsistencies. I apologize for that. It should work fine now with the WordCloud.jl v0.7.0. Please update it.
As for the documentation, it’s a bit hard for a non-native English speaker like me. I am help wanted.
p.s. There used to be an auto-generated docstrings in the Julia Hub, but it gone later, leaving only Readme. I don’t know why.

1 Like

I tried the online generator in the repo’s README, but got a mystic pattern like bellow. How should I use it correctly?

I don’t know why Pango choose that odd font when the random set font is unavailable. You can set a proper font in the fonts textbox or just set it to empty.