Skip to content

Instantly share code, notes, and snippets.

@majacaci00
Created November 8, 2017 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save majacaci00/98a52bce3bb8457f60a0613c855afb73 to your computer and use it in GitHub Desktop.
Save majacaci00/98a52bce3bb8457f60a0613c855afb73 to your computer and use it in GitHub Desktop.
embedded sf map
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Mario Javier Carrillo 2017-11-08 \n",
"\n",
"CPython 3.6.3\n",
"IPython 6.2.1\n",
"\n",
"matplotlib 2.1.0\n",
"numpy 1.13.3\n",
"pandas 0.21.0\n"
]
}
],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import mplleaflet\n",
"import seaborn as sns\n",
"\n",
"import prettyplotlib as ppl\n",
"\n",
"import imp\n",
"pd.set_option(\"max_columns\", None)\n",
"sns.set_style('whitegrid')\n",
"\n",
"%load_ext watermark\n",
"%matplotlib inline\n",
"%config InlineBackend.figure_format = 'retina'\n",
"%watermark -v -d -a 'Mario Javier Carrillo' -p matplotlib,numpy,pandas"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sfcrime = pd.read_pickle('../data/sfcrime.pkl')\n",
"sfcrime['Category'].replace(\"LARCENY/THEFT\",\"LARCENY_THEFT\", inplace=True )\n",
"sfcrime = sfcrime.rename(columns={'Y': 'latitude', 'X': 'longitude'})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plotter = imp.load_source('plotter', '../utils/plotting/maps_visual.py')\n",
"from plotter import sampling_data_points"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"frame_1, frame_2 = sampling_data_points(sfcrime, col_cat=\"Category\", category='DRUNKENNESS', col_time='year', \n",
" num_1=2016, num_2=2017, num_sample=1000)\n",
"fig = plt.figure(figsize=(20,15))\n",
"ax = fig.gca()\n",
"ax = plt.scatter(frame_1['longitude'], frame_1['latitude'], marker=\"o\", color=\"r\", s=20, linewidths=1)\n",
"ax = plt.scatter(frame_2['longitude'], frame_2['latitude'], marker=\"x\", color=\"black\", s=20, linewidths=1)\n",
"mplleaflet.display(fig=ax.figure)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:gds-scipy16]",
"language": "python",
"name": "conda-env-gds-scipy16-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment