|
22 | 22 | "metadata": {}, |
23 | 23 | "outputs": [], |
24 | 24 | "source": [ |
25 | | - "import sys\n", |
26 | 25 | "import os\n", |
27 | | - "sys.path.append(os.path.abspath('..'))\n", |
28 | | - "import numpy as np\n", |
29 | | - "import matplotlib.pyplot as plt\n", |
| 26 | + "import sys\n", |
| 27 | + "\n", |
| 28 | + "sys.path.append(os.path.abspath(\"..\"))\n", |
30 | 29 | "import geopandas\n", |
31 | | - "import pandas" |
| 30 | + "import matplotlib.pyplot as plt\n", |
| 31 | + "import numpy as np" |
32 | 32 | ] |
33 | 33 | }, |
34 | 34 | { |
|
46 | 46 | "metadata": {}, |
47 | 47 | "outputs": [], |
48 | 48 | "source": [ |
49 | | - "points = np.row_stack([(10.2, 5.1), (4.7, 2.2), (5.3, 5.7), (2.7, 5.3), (7,4)])\n", |
| 49 | + "points = np.row_stack([(10.2, 5.1), (4.7, 2.2), (5.3, 5.7), (2.7, 5.3), (7, 4)])\n", |
50 | 50 | "gdf = geopandas.GeoDataFrame(geometry=geopandas.points_from_xy(*points.T))" |
51 | 51 | ] |
52 | 52 | }, |
|
108 | 108 | } |
109 | 109 | ], |
110 | 110 | "source": [ |
111 | | - "f, ax =plt.subplots(1,3)\n", |
112 | | - "for i,g in enumerate((g1, g2, g3)):\n", |
| 111 | + "f, ax = plt.subplots(1, 3)\n", |
| 112 | + "for i, g in enumerate((g1, g2, g3)):\n", |
113 | 113 | " g.plot(gdf, ax=ax[i])\n", |
114 | 114 | " ax[i].set_title(f\"k = {i+1}\")" |
115 | 115 | ] |
|
128 | 128 | "outputs": [], |
129 | 129 | "source": [ |
130 | 130 | "import geodatasets\n", |
| 131 | + "\n", |
131 | 132 | "stores = geopandas.read_file(geodatasets.get_path(\"geoda liquor_stores\")).explode(\n", |
132 | 133 | " index_parts=False\n", |
133 | 134 | ")" |
|
261 | 262 | } |
262 | 263 | ], |
263 | 264 | "source": [ |
264 | | - "f, ax =plt.subplots(1,3)\n", |
265 | | - "for i,g in enumerate((g1, g5, g10)):\n", |
| 265 | + "f, ax = plt.subplots(1, 3)\n", |
| 266 | + "for i, g in enumerate((g1, g5, g10)):\n", |
266 | 267 | " g.plot(stores, ax=ax[i], nodes=False)\n", |
267 | 268 | " ax[i].set_title(f\"k = {(1, 5, 10)[i]}\")" |
268 | 269 | ] |
|
293 | 294 | "source": [ |
294 | 295 | "sources = stores.sample(100)\n", |
295 | 296 | "sinks = stores[~stores.index.isin(sources.index)].sample(100)\n", |
296 | | - "ax = sources.plot(color='red')\n", |
297 | | - "sinks.plot(color='blue', ax=ax)\n", |
| 297 | + "ax = sources.plot(color=\"red\")\n", |
| 298 | + "sinks.plot(color=\"blue\", ax=ax)\n", |
298 | 299 | "plt.show()" |
299 | 300 | ] |
300 | 301 | }, |
|
304 | 305 | "metadata": {}, |
305 | 306 | "outputs": [], |
306 | 307 | "source": [ |
307 | | - "from libpysal.graph._matching import _spatial_matching\n", |
308 | | - "import shapely" |
| 308 | + "import shapely\n", |
| 309 | + "\n", |
| 310 | + "from libpysal.graph._matching import _spatial_matching" |
309 | 311 | ] |
310 | 312 | }, |
311 | 313 | { |
|
334 | 336 | "metadata": {}, |
335 | 337 | "outputs": [], |
336 | 338 | "source": [ |
337 | | - "crosspattern_heads, crosspattern_tails, weights, mip = _spatial_matching(x=sink_coordinates, y = source_coordinates, n_matches=1, return_mip=True)" |
| 339 | + "crosspattern_heads, crosspattern_tails, weights, mip = _spatial_matching(\n", |
| 340 | + " x=sink_coordinates, y=source_coordinates, n_matches=1, return_mip=True\n", |
| 341 | + ")" |
338 | 342 | ] |
339 | 343 | }, |
340 | 344 | { |
|
364 | 368 | "outputs": [], |
365 | 369 | "source": [ |
366 | 370 | "lines = shapely.linestrings(\n", |
367 | | - " list( \n", |
368 | | - " zip(\n", |
369 | | - " map(list, source_coordinates[crosspattern_heads]),\n", |
370 | | - " map(list, sink_coordinates[crosspattern_tails])\n", |
| 371 | + " list(\n", |
| 372 | + " zip(\n", |
| 373 | + " map(list, source_coordinates[crosspattern_heads]),\n", |
| 374 | + " map(list, sink_coordinates[crosspattern_tails]),\n", |
| 375 | + " strict=False,\n", |
| 376 | + " )\n", |
371 | 377 | " )\n", |
372 | | - ")\n", |
373 | 378 | ")" |
374 | 379 | ] |
375 | 380 | }, |
|
390 | 395 | } |
391 | 396 | ], |
392 | 397 | "source": [ |
393 | | - "ax = sources.plot(color='red')\n", |
394 | | - "sinks.plot(color='blue', ax=ax)\n", |
395 | | - "geopandas.GeoSeries(lines).plot(linewidth=1, color='k', ax=ax)\n", |
| 398 | + "ax = sources.plot(color=\"red\")\n", |
| 399 | + "sinks.plot(color=\"blue\", ax=ax)\n", |
| 400 | + "geopandas.GeoSeries(lines).plot(linewidth=1, color=\"k\", ax=ax)\n", |
396 | 401 | "plt.show()" |
397 | 402 | ] |
398 | 403 | } |
|
0 commit comments