Saturday, December 14, 2013

Plot XKCD style charts from Google Ngram data using Python

In this Github repo you'll find two Python scripts, one of which can be used to fetch data from the Google Ngram Viewer and the other to create XKCD style plots using the CSV data returned by the first script.

I previously made a blog post introducing the script for retrieving data from the Google Ngram Viewer, but it now has a lot more functionality. With the exception of 1 or 2 advanced features that one can do using the Google Ngram Viewer web interface, the script is a fully function command line interface to the Google Ngram Viewer. To learn how to use the script, check out the README file in the Github repo.

The accompanying script provides automatic creation of XKCD style plots when retrieving ngram data using Simply add the -plot flag to your query and a line chart in a .png file will be created alongside the CSV data file.

For example, to create the plot shown above, you could run:

python railroad,radio,television,internet -startYear=1900 -endYear=2000 -plot -caseInsensitive

There are other ways to plot the ngram data as well, so read the plotting section of the README to learn more.

No comments:

Post a Comment