import numpy as np !head -n5 HurricaneHistoryData.csv year, storms, hurricanes, deaths, damage, retired = \ np.genfromtxt('HurricaneHistoryData.csv', delimiter=',', usecols=range(6), dtype=np.int, unpack=True, skip_header=1) year[:5] %pylab inline %config InlineBackend.figure_format = 'SVG' import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.plot(year, storms, label='Storms') ax.plot(year, hurricanes, label='Hurricanes') ax.plot(year, retired, label='Retired Names') ax.set_xlabel('Year') ax.legend(loc='upper left') tropical_storms = storms - hurricanes unretired_hurricanes = hurricanes - retired fig, ax = plt.subplots() ax.stackplot(year, retired, unretired_hurricanes, tropical_storms) ax.set_xlabel('Year') left = year - 0.5 fig, ax = plt.subplots() ax.bar(left=left, height=tropical_storms, width=1, linewidth=0, color='b', label='Storms') ax.bar(left=left, height=unretired_hurricanes, bottom=tropical_storms, width=1, linewidth=0, color='r', label='Hurricanes') ax.bar(left=left, height=retired, bottom=tropical_storms + unretired_hurricanes, width=1, linewidth=0, color='g', label='Retired') ax.set_xlabel('Year') ax.legend(loc='upper left', fontsize=10) left = year - 0.5 fig, ax = plt.subplots() ax.bar(left=left, height=tropical_storms, width=1, linewidth=0, color='b', label='Storms') ax.bar(left=left, height=unretired_hurricanes, bottom=tropical_storms, width=1, linewidth=0, color='r', label='Hurricanes') ax.bar(left=left, height=retired, bottom=tropical_storms + unretired_hurricanes, width=1, linewidth=0, color='g', label='Retired') ax.set_xlabel('Year') ax.legend(loc='upper left', fontsize=10) ax.set_xlim(year.min() - 0.5, year.max() + 0.5) left = year - 0.5 fig, ax = plt.subplots(figsize=(14, 4)) ax.bar(left=left, height=tropical_storms, width=1, linewidth=0, color='b', label='Storms') ax.bar(left=left, height=unretired_hurricanes, bottom=tropical_storms, width=1, linewidth=0, color='r', label='Hurricanes') ax.bar(left=left, height=retired, bottom=tropical_storms + unretired_hurricanes, width=1, linewidth=0, color='g', label='Retired') ax.set_xlabel('Year') ax.legend(loc='upper left', fontsize=10) ax.set_xlim(year.min() - 0.5, year.max() + 0.5) left = year - 0.5 fig, ax = plt.subplots(figsize=(14, 4)) ax.bar(left=left, height=tropical_storms, width=1, linewidth=0, color='b', label='Storms') ax.bar(left=left, height=unretired_hurricanes, bottom=tropical_storms, width=1, linewidth=0, color='r', label='Hurricanes') ax.bar(left=left, height=retired, bottom=tropical_storms + unretired_hurricanes, width=1, linewidth=0, color='g', label='Retired') ax.set_xlabel('Year') ax.legend(loc='upper left', fontsize=10) ax2 = ax.twinx() ax2.set_yscale('log') ax2.plot(year, damage, color='c', linewidth=2) ax2.set_ylabel('Damage (millions of USD)') ax.set_xlim(year.min() - 0.5, year.max() + 0.5) fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 6), sharex=True) # ax1 will be top plot, ax2 the bottom damage_line, = ax1.plot(year, damage, color='blue', label='Damage') ax1.set_ylabel('Damage (millions of USD)') ax1_right = ax1.twinx() deaths_line, = ax1_right.plot(year, deaths, color='red', label='Deaths') ax1_right.set_ylabel('Deaths') ax1.legend((damage_line, deaths_line), ('Damage', 'Deaths'), loc='upper left', fontsize=10) ax2.bar(left=left, height=tropical_storms, width=1, linewidth=0, color='b', label='Storms') ax2.bar(left=left, height=unretired_hurricanes, bottom=tropical_storms, width=1, linewidth=0, color='r', label='Hurricanes') ax2.bar(left=left, height=retired, bottom=tropical_storms + unretired_hurricanes, width=1, linewidth=0, color='g', label='Retired') ax2.set_xlabel('Year') ax2.set_xlim(year.min() - 0.5, year.max() + 0.5) ax2.legend(loc='upper left', fontsize=10) fig.tight_layout(h_pad=0) fig.savefig('hurricane_history.pdf')