#!/usr/bin/python3 """Plot data from HN “who is hiring”/“who wants to be hired” posts. This uses Matplotlib without Numpy. """ from matplotlib.pyplot import figure, plot, gca, savefig, xticks, legend, ylim from matplotlib.pyplot import subplots, ylabel import csv import sys def plot_hiring(data, outfilename): hiring = [int(n) for what, month, year, n in data if what == 'hiring'] hired = [int(n) for what, month, year, n in data if what == 'hired'] hired_months = ['%s%s' % (month[:3], year[-2:]) for what, month, year, n in data if what == 'hired'] months = ['%s%s' % (month[:3], year[-2:]) for what, month, year, n in data if what == 'hiring'] if months != hired_months: raise ValueError(data) subplots(figsize=(12, 9)) ylabel('comments in thread') ylim(0, 1300) plot(hiring[::-1], label='Who is hiring?') plot(hired[::-1], label='Who wants to be hired?') legend() xticks(range(len(months)), months[::-1], rotation='vertical') savefig(outfilename) def main(args): if len(args) != 3: sys.stderr.write(f"Usage: {args[0]} whoishiring.csv hiring.png") return 1 plot_hiring(list(csv.reader(open(args[1]))), args[2]) if __name__ == '__main__': sys.exit(main(sys.argv))