""" COMP 364 Lecture 16: Histograms Author: Mathieu Perreault """ import matplotlib.pyplot as plt import random, sys # Simple demo first. Data is generated randomly but could be something else. data = [random.random()*50. for i in range(50)] print data plt.figure() plt.title('Distribution of randomly generated numbers') plt.ylabel('Number of occurrences') plt.xlabel('Bins') plt.hist(data, bins=10,color='g') plt.show() """# Histogram demo. Will plot a histogram of line lengths and a scatter plot. lengths = [] for line in open(sys.argv[1]): line = line.strip('\n') lengths.append(len(line)) plt.figure() plt.subplot(2,1,1) plt.hist(lengths, bins=10) plt.subplot(2,1,2) plt.plot(range(len(lengths)),lengths,'g.') plt.show() """