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 getngrams.py
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 xkcd.py
script provides automatic creation of XKCD style plots when retrieving ngram data using getngrams.py
. 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 getngrams.py 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.