214

Context

My Questions

  • Is there an algorithm available that does what Wordle does?
  • If no, what are some alternatives that produces similar kinds of output?

Why I'm asking

  • just curious
  • want to learn
2
  • 1
    There's an alternate implementation, based on image processing here. Not very speedy, but very flexible and good for experimentation. (There's a full implementation given in Mathematica.)
    – Szabolcs
    Apr 27, 2012 at 9:09
  • 2
    I came up with my own (pretty simple) algorithm and blogged about it. Its written in Python and should be easy to customize. I tried to make it half-way efficient. !enter image description here Nov 9, 2012 at 19:52

13 Answers 13

514
+50

I'm the creator of Wordle. Here's how Wordle actually works:

Count the words, throw away boring words, and sort by the count, descending. Keep the top N words for some N. Assign each word a font size proportional to its count. Generate a Java2D Shape for each word, using the Java2D API.

Each word "wants" to be somewhere, such as "at some random x position in the vertical center". In decreasing order of frequency, do this for each word:

place the word where it wants to be
while it intersects any of the previously placed words
    move it one step along an ever-increasing spiral

That's it. The hard part is in doing the intersection-testing efficiently, for which I use last-hit caching, hierarchical bounding boxes, and a quadtree spatial index (all of which are things you can learn more about with some diligent googling).

Edit: As Reto Aebersold pointed out, there's now a book chapter, freely available, that covers this same territory: Beautiful Visualization, Chapter 3: Wordle

6
  • 7
    More information here: static.mrfeinberg.com/bv_ch03.pdf - Thanks Jonathan. Mar 5, 2011 at 15:28
  • Thanks for the info Jonathan - I'm fascinated by realtively simple algorithms that can create great visualisations like this. Apr 20, 2011 at 23:04
  • I'm still a bit puzzled on the "wants to be somewhere" part. Is the initial position of words really random?
    – adib
    Apr 11, 2012 at 10:11
  • Thank you for the explanation. What does "each word wants to be somewhere" mean?
    – Metaphor
    Sep 12, 2013 at 19:57
  • It means that some data structure, which represents the word to placed, starts out with a preferred x and y coordinate. Sep 22, 2013 at 19:53
38

Here's a really nice javascript one from Jason Davies that uses d3. You can even use webfonts with it.

Demo: http://www.jasondavies.com/wordcloud/

Github: https://github.com/jasondavies/d3-cloud

3
  • It's very easy to just copy the src=".js" files and reupload them for building onto or just using as is. Thanks for sharing and works great!
    – Michael d
    Jul 18, 2016 at 23:44
  • Is there a way to change the color palette to something more aesthetic? I tried modifying the js file from the JSON call from: colourlovers.com/api/palettes/random to colourlovers.com/api/palettes/top as the colourlovers' API recommends but the palette remained the same.
    – Michael d
    Jul 18, 2016 at 23:59
  • Here is a responsive working example based on the demo but with full control on words and color. For a custom color palette please use the commented code, instead. jsbin.com/kiwojayoye/1/edit?html,js,output Jan 3, 2017 at 0:54
32

I've implemented an algorithm as described by Jonathan Feinberg using python to create a tag cloud. It is far away from the beautiful clouds of wordle.net but it gives you an idea how it could be done.

You can find the project here.

2
  • Link (labs.atizo.com) is broken again. You really should post a sample image or two so we can see the comparison.
    – smci
    Oct 7, 2013 at 12:00
  • @RetoAebersold is there anyway to integrate this code with flask or django framework?
    – Mitul Shah
    Sep 2, 2016 at 12:04
31

I've created a Silverlight component that uses the algorithm Jonathan suggests here. The source code and example projects are all available on my blog:

http://whydoidoit.com

Color word cloud

My cloud lets you color and size words based on different weightings and it supports word selection (from a coordinate) and selected word highlighting. The source is yours to use as you see fit.

Example Word Cloud

2
14

I'm working on WordCram, a Processing library for making word clouds. It's pretty heavily influenced by Wordle, and is informed by the same PDF aeby linked to above. It handles the collision detection for you, and lets you focus on how you want your words laid out, colored, rotated, etc.

2
  • Does your service offer an API?
    – bart
    Feb 24, 2014 at 6:23
  • Sorry, WordCram doesn't have an API. It's a library, not a service. Jul 12, 2014 at 14:38
10

http://code.google.com/apis/visualization/documentation/gallery.html

Check out the word cloud visualization. Not as fancy as wordle.net but real easy to add to your site.

8

I was looking for a wordle-like visualization which would allow to assign color, initial position and size of a String related to other data, such as the relevance within a text - didn't find anything, but thanks to the information I found here (Especially Jonathan's explanation and aeby's link), I could finally implement 'Cloudio', which comes relatively close to wordle (at least I think so...) and offers the features I was looking for.

It is implemented with SWT and JFace, and I tried to integrate it into the MVC-model of JFace, such that you can set content- and label-providers to modify the layout of a cloud and add it to other Eclipse-plugins or RCP apps. You can also modify the way the initial position of a string is calculated, such that is not difficult to use it for cluster visualization or else. It is still poorly documented and limited in some ways (and I did the initial upload a few hours ago, so it might still be a bit buggy), but if you're interested, here's the link:

And here's a link to some created clouds, in case you want a quick impression: https://github.com/sschwieb/Cloudio/wiki/Example-Clouds

Cheers, Stephan

8

Here see my implementation of Wordle like cloud. It uses the same spiral algorithm and the QuadTree data structure.

http://sourcecodecloud.codeplex.com

or

http://www.codeproject.com/Articles/224231/Word-Cloud-Tag-Cloud-Generator-Control-for-NET-Win

2
  • sourcecodecloud is not downloadable,also second link is not working Mar 15, 2013 at 14:28
  • I verified first link's Source Code / Download. It worked. Second link was moved. Now fixed. Mar 15, 2013 at 21:28
7

Lion and Lamb is an open-source iOS app that creates word clouds using the most frequent words from a chosen book of the Bible.

It's based on the algorithm as described by Jonathan Feinberg. Hit testing does utilize a quad tree, but the bounding boxes are based on the glyph's bounding rectangle. I want to break the glyph down into many smaller bounding rects to enable word placement within a glyph's bounding box.

GitHub: https://github.com/PetahChristian/LionAndLamb

A word cloud of the Bible book of Revelation

4

I have a Tag Cloud generator here, which I call Disorganizer :)

Sources TagCloudService and the razor markup control and a WinForm for testing purposes that you can put in your blog, profile etc, with a little wrapper around it. It uses C# 4.0 & System.Drawing namespace heavily.

I created it because with the other cloud generators you cannot click on tags to navigate and cannot create hover animations, to show that they are clickable. Since showing hover animation in HTML is necessary for me (I'm doing this with overlay-ed, absolutely-positioned <a> tags) I haven't developed any-angle word display - they are either vertical or horizontal.

Warning :The above links may go invalid in a few months, I plan to slowly untie it from the surrounding project into a separate project.

You can see a working demo on this sample blog post, but it is incomplete, and in an incomplete site. Contact me if anyone wants to contribute, I will get on with separating it out asap.

2
  • Links have gone invalid. I like the UI on your blog.
    – Doug S
    Nov 15, 2013 at 17:33
  • Thanks, just fixed them
    – Zasz
    Nov 18, 2013 at 6:57
2

Here is yet another end-to-end implementation of wordle in Python 3 largely based on the initial outline by Jonathan Feinberg (QuadTrees, spirals, etc.).

The code (commented, with detailed ReadMe file) is freely available at this Github repository and this is a sample wordle created with the code.

Macbeth

1

I've implemented a word cloud generator called WordCloud.jl in Julia language. A brief description about its algorithm can be found here.
Unlike most other implementations, I designed it based on gradient optimization. It’s a non-greedy algorithm in which words can be further moved after they are positioned. Thus the size of the words and the shape and size of the background mask can be kept unchanged in the generation process. This makes the outputs more accurate and easy to customize. Furthermore, we can also generate some fancy outputs like these:
Comparison of Obama's and Trump's inaugural address and Wikipedia: Julia
comparison wordcloud

julia wordcloud

2
  • While this link may answer the question, it is better to include the essential parts of the algorithm description here and provide the link for reference. Apr 25, 2021 at 9:54
  • Thank you @nik7. I've added some algorithm description as you suggested.
    – guoyongzhi
    Apr 30, 2021 at 8:13
0

There is a pretty nice little JavaScript library made by Tim Dream:

https://github.com/timdream/wordcloud2.js/blob/gh-pages/API.md

It can create a word cloud on a canvas or with HTML tags with a lot of options to modify the result. It comes really close to wordle's output.

1
  • Can't you just do something on your own ? Where is the curiosity? Dead already Aug 12, 2022 at 12:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.