@@ -243,7 +243,8 @@ du shapefile utilisé :
243
243
``` {python}
244
244
paris = communes[communes.insee.str.startswith("75")]
245
245
246
- ax = paris.plot(figsize=(10, 10), alpha=0.5, edgecolor='blue')
246
+ fig,ax = plt.subplots(figsize=(10, 10))
247
+ paris.plot(ax = ax, alpha=0.5, edgecolor='blue')
247
248
ctx.add_basemap(ax, crs = paris.crs.to_string())
248
249
ax.set_axis_off()
249
250
ax
@@ -262,7 +263,7 @@ knitr::include_graphics("map_paris1.png")
262
263
On voit ainsi que les données pour Paris ne comportent pas d'arrondissement,
263
264
ce qui est limitant pour une analyse focalisée sur Paris. On va donc les
264
265
récupérer sur le site d'open data de la ville de Paris et les substituer
265
- à Paris
266
+ à Paris :
266
267
267
268
``` {python}
268
269
arrondissements = gpd.read_file("https://opendata.paris.fr/explore/dataset/arrondissements/download/?format=geojson&timezone=Europe/Berlin&lang=fr")
@@ -276,7 +277,10 @@ espéré
276
277
277
278
``` {python}
278
279
paris = communes[communes.insee.str.startswith("75")]
279
- ax = paris.plot(figsize=(10, 10), alpha=0.5, edgecolor='k')
280
+
281
+ fig,ax = plt.subplots(figsize=(10, 10))
282
+
283
+ paris.plot(ax = ax, alpha=0.5, edgecolor='k')
280
284
ctx.add_basemap(ax, crs = paris.crs.to_string())
281
285
ax.set_axis_off()
282
286
ax
@@ -315,25 +319,59 @@ communes['dep'] = communes.insee.str[:2]
315
319
316
320
On peut se rassurer en affichant les données sur la carte des communes d'Île-de-France.
317
321
318
- Découvrez ci-dessous par étape les différentes lignes de commandes permettant d'afficher une carte complète,
322
+ ``` {python, include = FALSE}
323
+ fig,ax = plt.subplots(figsize=(10, 10))
324
+ stations.sample(200).plot(ax = ax, color = 'red', alpha = 0.4, zorder=2)
325
+ communes[communes['dep'].isin(['75','92','93','94'])].plot(ax = ax, zorder=1, edgecolor = "black", facecolor="none",
326
+ color = None)
327
+ ctx.add_basemap(ax, crs = stations.crs.to_string(), source = ctx.providers.Stamen.Watercolor)
328
+ ax.set_axis_off()
329
+ ax
330
+ ```
331
+
332
+ ``` {python, echo = FALSE, include = FALSE}
333
+ plt.tight_layout(pad=0, h_pad = 0)
334
+ plt.savefig('map1.png', bbox_inches='tight')
335
+ ```
336
+
337
+ ``` {r, echo = FALSE}
338
+ knitr::include_graphics("map1.png")
339
+ ```
340
+
341
+
342
+ Découvrez ci-dessous par étape les différentes lignes de commandes permettant d'afficher cette carte complète,
319
343
étape par étape:
320
344
321
- 1 . Afficher le nuage de point de 200 stations vélibs prises au hasard
345
+ :one :
346
+ Afficher le nuage de points de 200 stations vélibs prises au hasard
322
347
323
- ``` {python}
324
- ax = stations.sample(200).plot(figsize = (10,10), color = 'red', alpha = 0.4, zorder=2)
348
+ ``` {python, include = FALSE}
349
+ fig,ax = plt.subplots(figsize=(10, 10))
350
+ stations.sample(200).plot(ax = ax, color = 'red', alpha = 0.4, zorder=2)
325
351
#communes[communes['dep'].isin(['75','92','93','94'])].plot(ax = ax, zorder=1, edgecolor = "black", facecolor="none",
326
352
# color = None)
327
353
#ctx.add_basemap(ax, crs = stations.crs.to_string(), source = ctx.providers.Stamen.Watercolor)
328
354
# ax.set_axis_off()
355
+ ax
356
+ ```
357
+
358
+ ``` {python, echo = FALSE, include = FALSE}
359
+ plt.tight_layout(pad=0, h_pad = 0)
360
+ plt.show()
361
+ plt.savefig('map2aa.png', bbox_inches='tight')
362
+ ```
363
+
364
+ ``` {r, echo = FALSE, include = FALSE}
365
+ knitr::include_graphics("map2aa.png")
329
366
```
330
367
331
368
332
369
:two :
333
370
Ajouter à cette couche, en dessous, les contours des communes
334
371
335
- ``` {python}
336
- ax = stations.sample(200).plot(figsize = (10,10), color = 'red', alpha = 0.4, zorder=2)
372
+ ``` {python, include = FALSE}
373
+ fig,ax = plt.subplots(figsize=(10, 10))
374
+ stations.sample(200).plot(ax = ax, color = 'red', alpha = 0.4, zorder=2)
337
375
communes[communes['dep'].isin(['75','92','93','94'])].plot(ax = ax, zorder=1, edgecolor = "black", facecolor="none",
338
376
color = None)
339
377
#ctx.add_basemap(ax, crs = stations.crs.to_string(), source = ctx.providers.Stamen.Watercolor)
343
381
344
382
``` {python, echo = FALSE, include = FALSE}
345
383
plt.tight_layout(pad=0, h_pad = 0)
384
+ plt.show()
346
385
plt.savefig('map2a.png', bbox_inches='tight')
347
386
```
348
387
349
- ``` {r, echo = FALSE}
388
+ ``` {r, echo = FALSE, include = FALSE }
350
389
knitr::include_graphics("map2a.png")
351
390
```
352
391
353
392
354
- 3 . Ajouter un fond de carte de type * open street map* grâce au package
393
+ :three :
394
+ Ajouter un fond de carte de type * open street map* grâce au package
355
395
` contextily `
356
396
357
- ``` {python}
358
- ax = stations.sample(200).plot(figsize = (10,10), color = 'red', alpha = 0.4, zorder=2)
397
+ ``` {python, include = FALSE}
398
+ fig,ax = plt.subplots(figsize=(10, 10))
399
+ stations.sample(200).plot(ax = ax, color = 'red', alpha = 0.4, zorder=2)
359
400
communes[communes['dep'].isin(['75','92','93','94'])].plot(ax = ax, zorder=1, edgecolor = "black", facecolor="none",
360
401
color = None)
361
402
ctx.add_basemap(ax, crs = stations.crs.to_string(), source = ctx.providers.Stamen.Watercolor)
@@ -372,28 +413,21 @@ plt.savefig('map3a.png', bbox_inches='tight')
372
413
knitr::include_graphics("map3a.png")
373
414
```
374
415
416
+ :four :
375
417
Ne reste plus qu'à retirer l'axe des coordonnées, qui n'est pas très
376
418
esthétique. Pour cela:
377
419
378
- ``` {python}
379
- ax = stations.sample(200).plot(figsize = (10,10), color = 'red', alpha = 0.4, zorder=2)
420
+ ``` {python, include = FALSE, eval = FALSE}
421
+ fig,ax = plt.subplots(figsize=(10, 10))
422
+ stations.sample(200).plot(ax = ax, color = 'red', alpha = 0.4, zorder=2)
380
423
communes[communes['dep'].isin(['75','92','93','94'])].plot(ax = ax, zorder=1, edgecolor = "black", facecolor="none",
381
424
color = None)
382
425
ctx.add_basemap(ax, crs = stations.crs.to_string(), source = ctx.providers.Stamen.Watercolor)
383
426
ax.set_axis_off()
384
427
ax
385
428
```
386
429
387
- * In fine* , on obtient la carte ci-dessous:
388
-
389
- ``` {python, echo = FALSE, include = FALSE}
390
- plt.tight_layout(pad=0, h_pad = 0)
391
- plt.savefig('map1.png', bbox_inches='tight')
392
- ```
393
-
394
- ``` {r, echo = FALSE}
395
- knitr::include_graphics("map1.png")
396
- ```
430
+ * In fine* , on obtient la carte désirée.
397
431
398
432
399
433
## Opérations sur les attributs
@@ -433,7 +467,8 @@ attribus avec la méthode `dissolve`:
433
467
434
468
435
469
``` {python}
436
- ax = communes[communes.dep != "97"].dissolve(by='dep', aggfunc='sum').plot(column = "surf_ha")
470
+ fig,ax = plt.subplots(figsize=(10, 10))
471
+ communes[communes.dep != "97"].dissolve(by='dep', aggfunc='sum').plot(ax = ax, column = "surf_ha")
437
472
ax.set_axis_off()
438
473
ax
439
474
```
@@ -569,7 +604,8 @@ communes = communes.set_crs(2154)
569
604
Alors que la reprojection (projection Albers: 5070) s'obtient de la manière suivante:
570
605
571
606
``` {python}
572
- ax = communes[communes.dep != "97"].dissolve(by='dep', aggfunc='sum').to_crs(5070).plot()
607
+ fig,ax = plt.subplots(figsize=(10, 10))
608
+ communes[communes.dep != "97"].dissolve(by='dep', aggfunc='sum').to_crs(5070).plot(ax = ax)
573
609
ax
574
610
```
575
611
@@ -595,7 +631,9 @@ nord-américain (et encore, pas dans son ensemble !).
595
631
596
632
``` {python, eval = TRUE}
597
633
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
598
- ax = world[world.continent == "North America"].to_crs(5070).plot(alpha = 0.2, edgecolor = "k")
634
+
635
+ fig,ax = plt.subplots(figsize=(10, 10))
636
+ world[world.continent == "North America"].to_crs(5070).plot(alpha = 0.2, edgecolor = "k", ax = ax)
599
637
ax
600
638
```
601
639
0 commit comments