# This just lets the output of the following code samples # display inline on this page.%pylab inline %pylab inline from pylab import * # Set default figure size for this notebook pylab.rcParams['figure.figsize'] = (8.0, 6.4) from pylab import * plot([1,2,3]) show() from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np # make sure the value of resolution is a lowercase L, # for 'low', not a numeral 1 map = Basemap(projection='ortho', lat_0=50, lon_0=-100, resolution='l', area_thresh=1000.0) map.drawcoastlines() plt.show() ###highlight=[12,13] from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np # make sure the value of resolution is a lowercase L, # for 'low', not a numeral 1 map = Basemap(projection='ortho', lat_0=50, lon_0=-100, resolution='l', area_thresh=1000.0) map.drawcoastlines() map.drawcountries() map.fillcontinents(color='coral') plt.show() ###highlight=[14] from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np # make sure the value of resolution is a lowercase L, # for 'low', not a numeral 1 map = Basemap(projection='ortho', lat_0=50, lon_0=-100, resolution='l', area_thresh=1000.0) map.drawcoastlines() map.drawcountries() map.fillcontinents(color='coral') map.drawmapboundary() plt.show() ###highlight=[16,17] from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np # make sure the value of resolution is a lowercase L, # for 'low', not a numeral 1 map = Basemap(projection='ortho', lat_0=50, lon_0=-100, resolution='l', area_thresh=1000.0) map.drawcoastlines() map.drawcountries() map.fillcontinents(color='coral') map.drawmapboundary() map.drawmeridians(np.arange(0, 360, 30)) map.drawparallels(np.arange(-90, 90, 30)) plt.show() ###highlight=[8,9] from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np # make sure the value of resolution is a lowercase L, # for 'low', not a numeral 1 map = Basemap(projection='ortho', lat_0=0, lon_0=-100, resolution='l', area_thresh=1000.0) map.drawcoastlines() map.drawcountries() map.fillcontinents(color='coral') map.drawmapboundary() map.drawmeridians(np.arange(0, 360, 30)) map.drawparallels(np.arange(-90, 90, 30)) plt.show() ###highlight=[8] from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np # make sure the value of resolution is a lowercase L, # for 'low', not a numeral 1 map = Basemap(projection='robin', lat_0=0, lon_0=-100, resolution='l', area_thresh=1000.0) map.drawcoastlines() map.drawcountries() map.fillcontinents(color='coral') map.drawmapboundary() map.drawmeridians(np.arange(0, 360, 30)) map.drawparallels(np.arange(-90, 90, 30)) plt.show() ###highlight=[10,11] from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np # make sure the value of resolution is a lowercase L, # for 'low', not a numeral 1 map = Basemap(projection='merc', lat_0=57, lon_0=-135, resolution = 'l', area_thresh = 1000.0, llcrnrlon=-136.25, llcrnrlat=56, urcrnrlon=-134.25, urcrnrlat=57.75) map.drawcoastlines() map.drawcountries() map.fillcontinents(color='coral') map.drawmapboundary() map.drawmeridians(np.arange(0, 360, 30)) map.drawparallels(np.arange(-90, 90, 30)) plt.show() ###highlight=[9] from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np # make sure the value of resolution is a lowercase L, # for 'low', not a numeral 1 map = Basemap(projection='merc', lat_0=57, lon_0=-135, resolution = 'h', area_thresh = 1000.0, llcrnrlon=-136.25, llcrnrlat=56, urcrnrlon=-134.25, urcrnrlat=57.75) map.drawcoastlines() map.drawcountries() map.fillcontinents(color='coral') map.drawmapboundary() map.drawmeridians(np.arange(0, 360, 30)) map.drawparallels(np.arange(-90, 90, 30)) plt.show() ###highlight=[9] from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np # make sure the value of resolution is a lowercase L, # for 'low', not a numeral 1 map = Basemap(projection='merc', lat_0=57, lon_0=-135, resolution = 'h', area_thresh = 0.1, llcrnrlon=-136.25, llcrnrlat=56, urcrnrlon=-134.25, urcrnrlat=57.75) map.drawcoastlines() map.drawcountries() map.fillcontinents(color='coral') map.drawmapboundary() map.drawmeridians(np.arange(0, 360, 30)) map.drawparallels(np.arange(-90, 90, 30)) plt.show() ###highlight=[16,17,18,19] from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np map = Basemap(projection='merc', lat_0 = 57, lon_0 = -135, resolution = 'h', area_thresh = 0.1, llcrnrlon=-136.25, llcrnrlat=56.0, urcrnrlon=-134.25, urcrnrlat=57.75) map.drawcoastlines() map.drawcountries() map.fillcontinents(color = 'coral') map.drawmapboundary() lon = -135.3318 lat = 57.0799 x,y = map(lon, lat) map.plot(x, y, 'bo', markersize=12) plt.show() ###highlight=[19] from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np map = Basemap(projection='merc', lat_0 = 57, lon_0 = -135, resolution = 'h', area_thresh = 0.1, llcrnrlon=-136.25, llcrnrlat=56.0, urcrnrlon=-134.25, urcrnrlat=57.75) map.drawcoastlines() map.drawcountries() map.fillcontinents(color = 'coral') map.drawmapboundary() lons = [-135.3318, -134.8331, -134.6572] lats = [57.0799, 57.0894, 56.2399] x,y = map(lons, lats) map.plot(x, y, 'bo', markersize=10) plt.show() ###highlight=[21,22,23] from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np map = Basemap(projection='merc', lat_0 = 57, lon_0 = -135, resolution = 'h', area_thresh = 0.1, llcrnrlon=-136.25, llcrnrlat=56.0, urcrnrlon=-134.25, urcrnrlat=57.75) map.drawcoastlines() map.drawcountries() map.fillcontinents(color = 'coral') map.drawmapboundary() lons = [-135.3318, -134.8331, -134.6572] lats = [57.0799, 57.0894, 56.2399] x,y = map(lons, lats) map.plot(x, y, 'bo', markersize=10) labels = ['Sitka', 'Baranof Warm Springs', 'Port Alexander'] for label, xpt, ypt in zip(labels, x, y): plt.text(xpt, ypt, label) plt.show() ###highlight=[23] from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np map = Basemap(projection='merc', lat_0 = 57, lon_0 = -135, resolution = 'h', area_thresh = 0.1, llcrnrlon=-136.25, llcrnrlat=56.0, urcrnrlon=-134.25, urcrnrlat=57.75) map.drawcoastlines() map.drawcountries() map.fillcontinents(color = 'coral') map.drawmapboundary() lons = [-135.3318, -134.8331, -134.6572] lats = [57.0799, 57.0894, 56.2399] x,y = map(lons, lats) map.plot(x, y, 'bo', markersize=10) labels = ['Sitka', 'Baranof Warm Springs', 'Port Alexander'] for label, xpt, ypt in zip(labels, x, y): plt.text(xpt+10000, ypt+5000, label) plt.show() ###highlight=[21,22,23,24,25,26] from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np map = Basemap(projection='merc', lat_0 = 57, lon_0 = -135, resolution = 'h', area_thresh = 0.1, llcrnrlon=-136.25, llcrnrlat=56.0, urcrnrlon=-134.25, urcrnrlat=57.75) map.drawcoastlines() map.drawcountries() map.fillcontinents(color = 'coral') map.drawmapboundary() lons = [-135.3318, -134.8331, -134.6572] lats = [57.0799, 57.0894, 56.2399] x,y = map(lons, lats) map.plot(x, y, 'bo', markersize=10) labels = ['Sitka', 'Baranof\n Warm Springs', 'Port Alexander'] x_offsets = [10000, -20000, -25000] y_offsets = [5000, -50000, -35000] for label, xpt, ypt, x_offset, y_offset in zip(labels, x, y, x_offsets, y_offsets): plt.text(xpt+x_offset, ypt+y_offset, label) plt.show() data_file = open('datasets/earthquake_data.csv') for index, line in enumerate(data_file.readlines()): print(line.split(',')) if index == 1: break # Open the earthquake data file. data_file = open('datasets/earthquake_data.csv') # Read each line in the file, and keep track of what line we are on. for index, line in enumerate(data_file.readlines()): # Split the data into items in a list. split_line = line.split(',') # Count the number of fields in each line. number_fields = len(split_line) print(number_fields, split_line) # Stop after the 5th line of data. if index == 5: break # Open the earthquake data file. data_file = open('datasets/earthquake_data.csv') # Create empty lists for the latitudes and longitudes. lats, lons = [], [] # Read through the entire file, skip the first line, # and pull out just the lats and lons. for index, line in enumerate(data_file.readlines()): if index > 0: lats.append(float(line.split(',')[1])) lons.append(float(line.split(',')[2])) # Display the first 5 lats and lons. print('lats', lats[0:5]) print('lons', lons[0:5]) import csv # Open the earthquake data file. filename = 'datasets/earthquake_data.csv' # Create empty lists for the latitudes and longitudes. lats, lons = [], [] # Read through the entire file, skip the first line, # and pull out just the lats and lons. with open(filename) as f: # Create a csv reader object. reader = csv.reader(f) # Ignore the header row. next(reader) # Store the latitudes and longitudes in the appropriate lists. for row in reader: lats.append(float(row[1])) lons.append(float(row[2])) # Display the first 5 lats and lons. print('lats', lats[0:5]) print('lons', lons[0:5]) import csv # Open the earthquake data file. filename = 'datasets/earthquake_data.csv' # Create empty lists for the latitudes and longitudes. lats, lons = [], [] # Read through the entire file, skip the first line, # and pull out just the lats and lons. with open(filename) as f: # Create a csv reader object. reader = csv.reader(f) # Ignore the header row. next(reader) # Store the latitudes and longitudes in the appropriate lists. for row in reader: lats.append(float(row[1])) lons.append(float(row[2])) # --- Build Map --- from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np map = Basemap(projection='robin', resolution = 'l', area_thresh = 1000.0, lat_0=0, lon_0=-130) map.drawcoastlines() map.drawcountries() map.fillcontinents(color = 'gray') map.drawmapboundary() map.drawmeridians(np.arange(0, 360, 30)) map.drawparallels(np.arange(-90, 90, 30)) x,y = map(lons, lats) map.plot(x, y, 'ro', markersize=6) plt.show() ###highlight=[9,24] import csv # Open the earthquake data file. filename = 'datasets/earthquake_data.csv' # Create empty lists for the data we are interested in. lats, lons = [], [] magnitudes = [] # Read through the entire file, skip the first line, # and pull out just the lats and lons. with open(filename) as f: # Create a csv reader object. reader = csv.reader(f) # Ignore the header row. next(reader) # Store the latitudes and longitudes in the appropriate lists. for row in reader: lats.append(float(row[1])) lons.append(float(row[2])) magnitudes.append(float(row[4])) # --- Build Map --- from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np map = Basemap(projection='robin', resolution = 'l', area_thresh = 1000.0, lat_0=0, lon_0=-130) map.drawcoastlines() map.drawcountries() map.fillcontinents(color = 'gray') map.drawmapboundary() map.drawmeridians(np.arange(0, 360, 30)) map.drawparallels(np.arange(-90, 90, 30)) x,y = map(lons, lats) map.plot(x, y, 'ro', markersize=6) plt.show() ###highlight=[40,41,42,43,44] import csv # Open the earthquake data file. filename = 'datasets/earthquake_data.csv' # Create empty lists for the data we are interested in. lats, lons = [], [] magnitudes = [] # Read through the entire file, skip the first line, # and pull out just the lats and lons. with open(filename) as f: # Create a csv reader object. reader = csv.reader(f) # Ignore the header row. next(reader) # Store the latitudes and longitudes in the appropriate lists. for row in reader: lats.append(float(row[1])) lons.append(float(row[2])) magnitudes.append(float(row[4])) # --- Build Map --- from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np map = Basemap(projection='robin', resolution = 'l', area_thresh = 1000.0, lat_0=0, lon_0=-130) map.drawcoastlines() map.drawcountries() map.fillcontinents(color = 'gray') map.drawmapboundary() map.drawmeridians(np.arange(0, 360, 30)) map.drawparallels(np.arange(-90, 90, 30)) min_marker_size = 2.5 for lon, lat, mag in zip(lons, lats, magnitudes): x,y = map(lon, lat) msize = mag * min_marker_size map.plot(x, y, 'ro', markersize=msize) plt.show() ###highlight=[31,32,33,34,35,36,37,38,39,54,55] import csv # Open the earthquake data file. filename = 'datasets/earthquake_data.csv' # Create empty lists for the data we are interested in. lats, lons = [], [] magnitudes = [] # Read through the entire file, skip the first line, # and pull out just the lats and lons. with open(filename) as f: # Create a csv reader object. reader = csv.reader(f) # Ignore the header row. next(reader) # Store the latitudes and longitudes in the appropriate lists. for row in reader: lats.append(float(row[1])) lons.append(float(row[2])) magnitudes.append(float(row[4])) # --- Build Map --- from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np def get_marker_color(magnitude): # Returns green for small earthquakes, yellow for moderate # earthquakes, and red for significant earthquakes. if magnitude < 3.0: return ('go') elif magnitude < 5.0: return ('yo') else: return ('ro') map = Basemap(projection='robin', resolution = 'l', area_thresh = 1000.0, lat_0=0, lon_0=-130) map.drawcoastlines() map.drawcountries() map.fillcontinents(color = 'gray') map.drawmapboundary() map.drawmeridians(np.arange(0, 360, 30)) map.drawparallels(np.arange(-90, 90, 30)) min_marker_size = 2.5 for lon, lat, mag in zip(lons, lats, magnitudes): x,y = map(lon, lat) msize = mag * min_marker_size marker_string = get_marker_color(mag) map.plot(x, y, marker_string, markersize=msize) plt.show() ###highlight=[10,26,59,60,61] import csv # Open the earthquake data file. filename = 'datasets/earthquake_data.csv' # Create empty lists for the data we are interested in. lats, lons = [], [] magnitudes = [] timestrings = [] # Read through the entire file, skip the first line, # and pull out just the lats and lons. with open(filename) as f: # Create a csv reader object. reader = csv.reader(f) # Ignore the header row. next(reader) # Store the latitudes and longitudes in the appropriate lists. for row in reader: lats.append(float(row[1])) lons.append(float(row[2])) magnitudes.append(float(row[4])) timestrings.append(row[0]) # --- Build Map --- from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np def get_marker_color(magnitude): # Returns green for small earthquakes, yellow for moderate # earthquakes, and red for significant earthquakes. if magnitude < 3.0: return ('go') elif magnitude < 5.0: return ('yo') else: return ('ro') map = Basemap(projection='robin', resolution = 'l', area_thresh = 1000.0, lat_0=0, lon_0=-130) map.drawcoastlines() map.drawcountries() map.fillcontinents(color = 'gray') map.drawmapboundary() map.drawmeridians(np.arange(0, 360, 30)) map.drawparallels(np.arange(-90, 90, 30)) min_marker_size = 2.5 for lon, lat, mag in zip(lons, lats, magnitudes): x,y = map(lon, lat) msize = mag * min_marker_size marker_string = get_marker_color(mag) map.plot(x, y, marker_string, markersize=msize) title_string = "Earthquakes of Magnitude 1.0 or Greater\n" title_string += "%s through %s" % (timestrings[-1], timestrings[0]) plt.title(title_string) plt.show() ###highlight=[60,63,64] import csv # Open the earthquake data file. filename = 'datasets/earthquake_data.csv' # Create empty lists for the data we are interested in. lats, lons = [], [] magnitudes = [] timestrings = [] # Read through the entire file, skip the first line, # and pull out just the lats and lons. with open(filename) as f: # Create a csv reader object. reader = csv.reader(f) # Ignore the header row. next(reader) # Store the latitudes and longitudes in the appropriate lists. for row in reader: lats.append(float(row[1])) lons.append(float(row[2])) magnitudes.append(float(row[4])) timestrings.append(row[0]) # --- Build Map --- from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np def get_marker_color(magnitude): # Returns green for small earthquakes, yellow for moderate # earthquakes, and red for significant earthquakes. if magnitude < 3.0: return ('go') elif magnitude < 5.0: return ('yo') else: return ('ro') map = Basemap(projection='robin', resolution = 'l', area_thresh = 1000.0, lat_0=0, lon_0=-130) map.drawcoastlines() map.drawcountries() map.fillcontinents(color = 'gray') map.drawmapboundary() map.drawmeridians(np.arange(0, 360, 30)) map.drawparallels(np.arange(-90, 90, 30)) min_marker_size = 2.5 for lon, lat, mag in zip(lons, lats, magnitudes): x,y = map(lon, lat) msize = mag * min_marker_size marker_string = get_marker_color(mag) map.plot(x, y, marker_string, markersize=msize) title_string = "Earthquakes of Magnitude 1.0 or Greater\n" title_string += "%s through %s" % (timestrings[-1][:10], timestrings[0][:10]) plt.title(title_string) # Make this final plot larger. figsize(24, 18) plt.show() ###highlight=[47,48,53] import csv # Open the earthquake data file. filename = 'datasets/earthquake_data.csv' # Create empty lists for the data we are interested in. lats, lons = [], [] magnitudes = [] timestrings = [] # Read through the entire file, skip the first line, # and pull out just the lats and lons. with open(filename) as f: # Create a csv reader object. reader = csv.reader(f) # Ignore the header row. next(reader) # Store the latitudes and longitudes in the appropriate lists. for row in reader: lats.append(float(row[1])) lons.append(float(row[2])) magnitudes.append(float(row[4])) timestrings.append(row[0]) # --- Build Map --- from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np def get_marker_color(magnitude): # Returns green for small earthquakes, yellow for moderate # earthquakes, and red for significant earthquakes. if magnitude < 3.0: return ('go') elif magnitude < 5.0: return ('yo') else: return ('ro') map = Basemap(projection='robin', resolution = 'l', area_thresh = 1000.0, lat_0=0, lon_0=-130) map.drawcoastlines() map.drawcountries() #map.fillcontinents(color = 'gray') map.bluemarble() map.drawmapboundary() map.drawmeridians(np.arange(0, 360, 30)) map.drawparallels(np.arange(-90, 90, 30)) min_marker_size = 2.25 for lon, lat, mag in zip(lons, lats, magnitudes): x,y = map(lon, lat) msize = mag * min_marker_size marker_string = get_marker_color(mag) map.plot(x, y, marker_string, markersize=msize) title_string = "Earthquakes of Magnitude 1.0 or Greater\n" title_string += "%s through %s" % (timestrings[-1][:10], timestrings[0][:10]) plt.title(title_string) plt.show()