# Letter frequencies in Moby Dick

The following program produces a bar chart of letter frequencies in the English language, estimated by analysis of the text of Moby Dick (available as a free download from Project Gutenberg). The vertical bars are centered, and labelled by letter.

import numpy as np
import matplotlib.pyplot as plt

text_file = 'moby-dick.txt'

letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
# Initialize the dictionary of letter counts: {'A': 0, 'B': 0, ...}
lcount = dict([(l, 0) for l in letters])

# Read in the text and count the letter occurences
try:
lcount[l.upper()] += 1
except KeyError:
# Ignore characters that are not letters
pass
# The total number of letters
norm = sum(lcount.values())

fig = plt.figure()