Created
November 16, 2017 14:02
-
-
Save afonsoaugusto/592af1e377d427220108b219da0c3269 to your computer and use it in GitHub Desktop.
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import matplotlib.pyplot as plt\n", | |
"from mpl_toolkits.basemap import Basemap\n", | |
"import pandas as pd\n", | |
"import io\n", | |
"%matplotlib inline\n", | |
"\n", | |
"u = u\"\"\"latitude,longitude\n", | |
"42.357778,-71.059444\n", | |
"39.952222,-75.163889\n", | |
"25.787778,-80.224167\n", | |
"30.267222, -97.763889\"\"\"\n", | |
"\n", | |
"# read in data to use for plotted points\n", | |
"buildingdf = pd.read_csv(io.StringIO(u), delimiter=\",\")\n", | |
"lat = buildingdf['latitude'].values\n", | |
"lon = buildingdf['longitude'].values\n", | |
"\n", | |
"# determine range to print based on min, max lat and lon of the data\n", | |
"margin = 2 # buffer to add to the range\n", | |
"lat_min = min(lat) - margin\n", | |
"lat_max = max(lat) + margin\n", | |
"lon_min = min(lon) - margin\n", | |
"lon_max = max(lon) + margin\n", | |
"\n", | |
"# create map using BASEMAP\n", | |
"m = Basemap(llcrnrlon=lon_min,\n", | |
" llcrnrlat=lat_min,\n", | |
" urcrnrlon=lon_max,\n", | |
" urcrnrlat=lat_max,\n", | |
" lat_0=(lat_max - lat_min)/2,\n", | |
" lon_0=(lon_max-lon_min)/2,\n", | |
" projection='merc',\n", | |
" resolution = 'h',\n", | |
" area_thresh=10000.,\n", | |
" )\n", | |
"m.drawcoastlines()\n", | |
"m.drawcountries()\n", | |
"m.drawstates()\n", | |
"m.drawmapboundary(fill_color='#46bcec')\n", | |
"m.fillcontinents(color = 'white',lake_color='#46bcec')\n", | |
"# convert lat and lon to map projection coordinates\n", | |
"lons, lats = m(lon, lat)\n", | |
"# plot points as red dots\n", | |
"m.scatter(lons, lats, marker = 'o', color='r', zorder=5)\n", | |
"plt.show()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment