Skip to content

Instantly share code, notes, and snippets.

@saliksyed
Last active June 29, 2017 11:38
Show Gist options
  • Save saliksyed/41aed75a420ab12cd4e42c8da0015f7a to your computer and use it in GitHub Desktop.
Save saliksyed/41aed75a420ab12cd4e42c8da0015f7a to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
# Open the file with all the airports and read every line
data = open("airports.dat", "r").readlines()
# make an array to store the final data
final_data = []
# go through each row and extract the airport altitude
for row in data:
row_items = row.split(",") # split by the comma
final_data.append(float(row_items[8]))
num_bins = 50
fig, ax = plt.subplots()
# the histogram of the data
n, bins, patches = ax.hist(final_data, num_bins, normed=0)
# add a 'best fit' lin
ax.set_xlabel('Altitude')
ax.set_ylabel('Number of Airports')
ax.set_title(r'Histogram of Elevations of Airports')
# Tweak spacing to prevent clipping of ylabel
fig.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment