from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import csv #get list of temple name, location, dedication data, lat, and lon path = '/home/sm/Desktop/temple_data.csv' temples = [] #create a list to store the temple data from the spread sheet with open(path, 'rb') as csvfile: #open the csv file temple_data = csv.reader(csvfile, delimiter=',', quotechar='"') #load temple data for temple in temple_data: #iterate through data to change year to int try: year = int(temple[2][-4:]) temples.append((temple[0],temple[1],year,temple[3],temple[4])) except: temples.append((temple[0],temple[1],2016,temple[3],temple[4])) #sort list by dedication date temples = sorted(temples, key=lambda temple: temple[2]) year = temples[0][2] - 10 #ten years before the earliest dedication date while year < 2040: #iterate through years, mapping each temple m = Basemap(projection='mill') #create map (m) m.drawcoastlines() #m.drawcountries() #m.bluemarble() print 'Year: ', year #print the year in the terminal (to monitor progress) temples_plotted = 0 #let's count the number of temples on the map for temple in temples: #check to see of each temple should be plotted if temple[2] <= year: #if the temple was built x, y = m(float(temple[4]), float(temple[3])) #interpolate coordinates size = temple[2]-year+15 #more recently built temples are larger if size<5: size=5 #minimum size is 5 m.plot(x, y, 'go', markersize=size, alpha=1, color='r') #plot the temple on the map if temple[2]==2016: m.plot(x, y, 'go', markersize=size, alpha=1, color='b') #future planned temples are blue temples_plotted += 1 #make the title y = 2016 if year < y: y = year plt.text(0,0,' # of temples built:'+str(temples_plotted)) plt.title('Mormon Temples built by year '+str(y)) #plt.show() #show the map plt.savefig('/home/sm/Desktop/mormon_img/'+str(year)+'.png') #save the map plt.clf() #clear the plot year+=1 #go to the next year and repeat