Created
December 2, 2013 21:03
-
-
Save zpconn/7758924 to your computer and use it in GitHub Desktop.
Generates a scatter plot of lat/lon data on a map of the United States.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mpl_toolkits.basemap import Basemap | |
from shapely.geometry import Point, MultiPoint | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
x = [] | |
y = [] | |
with open('data.tsv', 'r') as fp: | |
for line in fp: | |
s = line.split('\t') | |
pairs = zip(*[iter(s)]*2) | |
d = dict(x[0:] for x in reversed(pairs)) | |
if 'lat' in d and 'lon' in d: | |
x.append(float(d['lat'])) | |
y.append(float(d['lon'])) | |
fp.close() | |
m = Basemap( | |
projection='merc', | |
ellps = 'WGS84', | |
llcrnrlon=-130, | |
llcrnrlat=25, | |
urcrnrlon=-60, | |
urcrnrlat=50, | |
lat_ts=0, | |
resolution='i', | |
suppress_ticks=True) | |
map_points = pd.Series([Point(m(mapped_x, mapped_y)) for mapped_x, mapped_y in zip(y, x)]) | |
amre_points = MultiPoint(list(map_points.values)) | |
plt.clf() | |
fig = plt.figure() | |
ax = fig.add_subplot(111, axisbg='w', frame_on=False) | |
fig.set_size_inches(18.5, 10.5) | |
dev = m.scatter( | |
[geom.x for geom in map_points], | |
[geom.y for geom in map_points], | |
20, marker='o', lw=.25, | |
facecolor='#33ccff', edgecolor='w', | |
alpha=0.9,antialiased=True, | |
zorder=3) | |
m.fillcontinents(color='#555555') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment