Skip to content

Commit 5572db9

Browse files
committed
update demo nb pandana plot to use cartopy and matplotlib directly
1 parent 3581d33 commit 5572db9

File tree

2 files changed

+56
-92
lines changed

2 files changed

+56
-92
lines changed

demo/simple_example.ipynb

+55-92
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"- Loading a network from disk\n",
7070
"- Visualizing the network\n",
7171
"- Adding average headways to network travel time\n",
72-
"- Using a UrbanAccess network with Pandana"
72+
"- Using an UrbanAccess network with Pandana"
7373
]
7474
},
7575
{
@@ -82,6 +82,9 @@
8282
"matplotlib.use('agg') # allows notebook to be tested in Travis\n",
8383
"\n",
8484
"import pandas as pd\n",
85+
"import cartopy.crs as ccrs\n",
86+
"import cartopy\n",
87+
"import matplotlib.pyplot as plt\n",
8588
"import pandana as pdna\n",
8689
"import time\n",
8790
"\n",
@@ -95,20 +98,6 @@
9598
"%matplotlib inline"
9699
]
97100
},
98-
{
99-
"cell_type": "code",
100-
"execution_count": null,
101-
"metadata": {
102-
"collapsed": true
103-
},
104-
"outputs": [],
105-
"source": [
106-
"# Pandana currently uses depreciated parameters in matplotlib, this hides the warning until its fixed\n",
107-
"import warnings\n",
108-
"import matplotlib.cbook\n",
109-
"warnings.filterwarnings(\"ignore\",category=matplotlib.cbook.mplDeprecation)"
110-
]
111-
},
112101
{
113102
"cell_type": "markdown",
114103
"metadata": {
@@ -146,9 +135,7 @@
146135
{
147136
"cell_type": "code",
148137
"execution_count": null,
149-
"metadata": {
150-
"collapsed": true
151-
},
138+
"metadata": {},
152139
"outputs": [],
153140
"source": [
154141
"settings.log_console = True"
@@ -166,9 +153,7 @@
166153
{
167154
"cell_type": "code",
168155
"execution_count": null,
169-
"metadata": {
170-
"collapsed": true
171-
},
156+
"metadata": {},
172157
"outputs": [],
173158
"source": [
174159
"settings.log_console = False"
@@ -506,9 +491,7 @@
506491
{
507492
"cell_type": "code",
508493
"execution_count": null,
509-
"metadata": {
510-
"collapsed": true
511-
},
494+
"metadata": {},
512495
"outputs": [],
513496
"source": [
514497
"urbanaccess_net = ua.network.ua_network"
@@ -1218,9 +1201,7 @@
12181201
{
12191202
"cell_type": "code",
12201203
"execution_count": null,
1221-
"metadata": {
1222-
"collapsed": true
1223-
},
1204+
"metadata": {},
12241205
"outputs": [],
12251206
"source": [
12261207
"blocks_subset['node_id'] = transit_ped_net.get_node_ids(blocks_subset['x'], blocks_subset['y'])"
@@ -1250,9 +1231,7 @@
12501231
{
12511232
"cell_type": "code",
12521233
"execution_count": null,
1253-
"metadata": {
1254-
"collapsed": true
1255-
},
1234+
"metadata": {},
12561235
"outputs": [],
12571236
"source": [
12581237
"transit_ped_net.set(blocks_subset.node_id, variable = blocks_subset.jobs, name='jobs')"
@@ -1320,23 +1299,31 @@
13201299
{
13211300
"cell_type": "code",
13221301
"execution_count": null,
1323-
"metadata": {
1324-
"scrolled": true
1325-
},
1302+
"metadata": {},
13261303
"outputs": [],
13271304
"source": [
1328-
"# s_time = time.time()\n",
1329-
"# transit_ped_net.plot(jobs_15, \n",
1330-
"# plot_type='scatter',\n",
1331-
"# fig_kwargs={'figsize':[20,20]},\n",
1332-
"# bmap_kwargs={'epsg':'26943','resolution':'h'},\n",
1333-
"# plot_kwargs={'cmap':'gist_heat_r','s':4,'edgecolor':'none'})\n",
1334-
"# print('Took {:,.2f} seconds'.format(time.time() - s_time))"
1305+
"s_time = time.time()\n",
1306+
"\n",
1307+
"fig = plt.subplots(figsize=(20,20))\n",
1308+
"\n",
1309+
"data_crs = ccrs.PlateCarree()\n",
1310+
"ax = plt.axes(projection=ccrs.epsg(26943))\n",
1311+
"ax.add_feature(cartopy.feature.GSHHSFeature(scale='full'), edgecolor='grey')\n",
1312+
"\n",
1313+
"plt.scatter(transit_ped_net.nodes_df.x, transit_ped_net.nodes_df.y, \n",
1314+
" c=jobs_15, s=4, cmap='gist_heat_r', edgecolor='none', transform=data_crs)\n",
1315+
"cb = plt.colorbar()\n",
1316+
"\n",
1317+
"print('Took {:,.2f} seconds'.format(time.time() - s_time))"
13351318
]
13361319
},
13371320
{
13381321
"cell_type": "markdown",
1339-
"metadata": {},
1322+
"metadata": {
1323+
"pycharm": {
1324+
"name": "#%% md\n"
1325+
}
1326+
},
13401327
"source": [
13411328
"### Jobs accessible within 30 minutes"
13421329
]
@@ -1347,13 +1334,19 @@
13471334
"metadata": {},
13481335
"outputs": [],
13491336
"source": [
1350-
"# s_time = time.time()\n",
1351-
"# transit_ped_net.plot(jobs_30, \n",
1352-
"# plot_type='scatter',\n",
1353-
"# fig_kwargs={'figsize':[20,20]},\n",
1354-
"# bmap_kwargs={'epsg':'26943','resolution':'h'},\n",
1355-
"# plot_kwargs={'cmap':'gist_heat_r','s':4,'edgecolor':'none'})\n",
1356-
"# print('Took {:,.2f} seconds'.format(time.time() - s_time))"
1337+
"s_time = time.time()\n",
1338+
"\n",
1339+
"fig = plt.subplots(figsize=(20,20))\n",
1340+
"\n",
1341+
"data_crs = ccrs.PlateCarree()\n",
1342+
"ax = plt.axes(projection=ccrs.epsg(26943))\n",
1343+
"ax.add_feature(cartopy.feature.GSHHSFeature(scale='full'), edgecolor='grey')\n",
1344+
"\n",
1345+
"plt.scatter(transit_ped_net.nodes_df.x, transit_ped_net.nodes_df.y, \n",
1346+
" c=jobs_30, s=4, cmap='gist_heat_r', edgecolor='none', transform=data_crs)\n",
1347+
"cb = plt.colorbar()\n",
1348+
"\n",
1349+
"print('Took {:,.2f} seconds'.format(time.time() - s_time))"
13571350
]
13581351
},
13591352
{
@@ -1369,50 +1362,20 @@
13691362
"metadata": {},
13701363
"outputs": [],
13711364
"source": [
1372-
"# s_time = time.time()\n",
1373-
"# transit_ped_net.plot(jobs_45, \n",
1374-
"# plot_type='scatter',\n",
1375-
"# fig_kwargs={'figsize':[20,20]},\n",
1376-
"# bmap_kwargs={'epsg':'26943','resolution':'h'},\n",
1377-
"# plot_kwargs={'cmap':'gist_heat_r','s':4,'edgecolor':'none'})\n",
1378-
"# print('Took {:,.2f} seconds'.format(time.time() - s_time))"
1365+
"s_time = time.time()\n",
1366+
"\n",
1367+
"fig = plt.subplots(figsize=(20,20))\n",
1368+
"\n",
1369+
"data_crs = ccrs.PlateCarree()\n",
1370+
"ax = plt.axes(projection=ccrs.epsg(26943))\n",
1371+
"ax.add_feature(cartopy.feature.GSHHSFeature(scale='full'), edgecolor='grey')\n",
1372+
"\n",
1373+
"plt.scatter(transit_ped_net.nodes_df.x, transit_ped_net.nodes_df.y, \n",
1374+
" c=jobs_45, s=4, cmap='gist_heat_r', edgecolor='none', transform=data_crs)\n",
1375+
"cb = plt.colorbar()\n",
1376+
"\n",
1377+
"print('Took {:,.2f} seconds'.format(time.time() - s_time))"
13791378
]
1380-
},
1381-
{
1382-
"cell_type": "code",
1383-
"execution_count": null,
1384-
"metadata": {
1385-
"collapsed": true
1386-
},
1387-
"outputs": [],
1388-
"source": []
1389-
},
1390-
{
1391-
"cell_type": "code",
1392-
"execution_count": null,
1393-
"metadata": {
1394-
"collapsed": true
1395-
},
1396-
"outputs": [],
1397-
"source": []
1398-
},
1399-
{
1400-
"cell_type": "code",
1401-
"execution_count": null,
1402-
"metadata": {
1403-
"collapsed": true
1404-
},
1405-
"outputs": [],
1406-
"source": []
1407-
},
1408-
{
1409-
"cell_type": "code",
1410-
"execution_count": null,
1411-
"metadata": {
1412-
"collapsed": true
1413-
},
1414-
"outputs": [],
1415-
"source": []
14161379
}
14171380
],
14181381
"metadata": {
@@ -1436,4 +1399,4 @@
14361399
},
14371400
"nbformat": 4,
14381401
"nbformat_minor": 1
1439-
}
1402+
}

requirements-dev.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
pytest
55
pycodestyle
66
jupyter
7+
cartopy
78

89
# building documentation
910
numpydoc

0 commit comments

Comments
 (0)