Skip to content

Commit 735e677

Browse files
Règle problème des cartes qui s'affichent pas (#165)
* define ax * là * autres * afficher chunk * Automated changes * update * Automated changes * tentative diff * diff origin master * try * head * cat file * list new files * rm subset * Automated changes * inversion ordre * Automated changes * update * Automated changes Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 6cdb336 commit 735e677

File tree

4 files changed

+72
-31
lines changed

4 files changed

+72
-31
lines changed

.github/workflows/netlify-test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ jobs:
3737
conda list
3838
- name: Build to md
3939
run: |
40+
git diff --name-only origin/master origin/${GITHUB_HEAD_REF} >> diff.txt
41+
cat diff.txt
4042
Rscript -e 'source("./build/build_light.R")'
4143
- name: Clean files with Python function
4244
run: |

build/build_light.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
content_rmd <- list.files("./content/course", recursive = TRUE, pattern = "*.Rmd", full.names = TRUE)
1+
content_rmd <- readLines("diff.txt")
2+
content_rmd <- content_rmd[startsWith(content_rmd, "content/course")]
3+
content_rmd <- content_rmd[endsWith(content_rmd, ".Rmd")]
24
content_rmd <- content_rmd[!grepl("/git/", content_rmd)]
35
content_rmd <- content_rmd[!grepl("06a_exo_supp_webscraping.", content_rmd)]
4-
content_rmd <- content_rmd[8:9]
56

67
file.remove(
78
gsub(

content/course/manipulation/03_geopandas_TP.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ print_badges()
4141

4242
Installations préalables :
4343

44-
```{python, eval=FALSE, echo=TRUE}
44+
```{python, eval=FALSE, echo=TRUE, include=TRUE}
4545
!pip install pandas fiona shapely pyproj rtree # à faire obligatoirement en premier pour utiliser rtree ou pygeos pour les jointures spatiales
4646
!pip install contextily
4747
!pip install geopandas

content/course/manipulation/03_geopandas_tutorial.Rmd

Lines changed: 66 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ du shapefile utilisé :
243243
```{python}
244244
paris = communes[communes.insee.str.startswith("75")]
245245
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')
247248
ctx.add_basemap(ax, crs = paris.crs.to_string())
248249
ax.set_axis_off()
249250
ax
@@ -262,7 +263,7 @@ knitr::include_graphics("map_paris1.png")
262263
On voit ainsi que les données pour Paris ne comportent pas d'arrondissement,
263264
ce qui est limitant pour une analyse focalisée sur Paris. On va donc les
264265
récupérer sur le site d'open data de la ville de Paris et les substituer
265-
à Paris
266+
à Paris :
266267

267268
```{python}
268269
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é
276277

277278
```{python}
278279
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')
280284
ctx.add_basemap(ax, crs = paris.crs.to_string())
281285
ax.set_axis_off()
282286
ax
@@ -315,25 +319,59 @@ communes['dep'] = communes.insee.str[:2]
315319

316320
On peut se rassurer en affichant les données sur la carte des communes d'Île-de-France.
317321

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,
319343
étape par étape:
320344

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
322347

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)
325351
#communes[communes['dep'].isin(['75','92','93','94'])].plot(ax = ax, zorder=1, edgecolor = "black", facecolor="none",
326352
# color = None)
327353
#ctx.add_basemap(ax, crs = stations.crs.to_string(), source = ctx.providers.Stamen.Watercolor)
328354
# 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")
329366
```
330367

331368

332369
:two:
333370
Ajouter à cette couche, en dessous, les contours des communes
334371

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)
337375
communes[communes['dep'].isin(['75','92','93','94'])].plot(ax = ax, zorder=1, edgecolor = "black", facecolor="none",
338376
color = None)
339377
#ctx.add_basemap(ax, crs = stations.crs.to_string(), source = ctx.providers.Stamen.Watercolor)
@@ -343,19 +381,22 @@ ax
343381

344382
```{python, echo = FALSE, include = FALSE}
345383
plt.tight_layout(pad=0, h_pad = 0)
384+
plt.show()
346385
plt.savefig('map2a.png', bbox_inches='tight')
347386
```
348387

349-
```{r, echo = FALSE}
388+
```{r, echo = FALSE, include = FALSE}
350389
knitr::include_graphics("map2a.png")
351390
```
352391

353392

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
355395
`contextily`
356396

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)
359400
communes[communes['dep'].isin(['75','92','93','94'])].plot(ax = ax, zorder=1, edgecolor = "black", facecolor="none",
360401
color = None)
361402
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')
372413
knitr::include_graphics("map3a.png")
373414
```
374415

416+
:four:
375417
Ne reste plus qu'à retirer l'axe des coordonnées, qui n'est pas très
376418
esthétique. Pour cela:
377419

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)
380423
communes[communes['dep'].isin(['75','92','93','94'])].plot(ax = ax, zorder=1, edgecolor = "black", facecolor="none",
381424
color = None)
382425
ctx.add_basemap(ax, crs = stations.crs.to_string(), source = ctx.providers.Stamen.Watercolor)
383426
ax.set_axis_off()
384427
ax
385428
```
386429

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.
397431

398432

399433
## Opérations sur les attributs
@@ -433,7 +467,8 @@ attribus avec la méthode `dissolve`:
433467

434468

435469
```{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")
437472
ax.set_axis_off()
438473
ax
439474
```
@@ -569,7 +604,8 @@ communes = communes.set_crs(2154)
569604
Alors que la reprojection (projection Albers: 5070) s'obtient de la manière suivante:
570605

571606
```{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)
573609
ax
574610
```
575611

@@ -595,7 +631,9 @@ nord-américain (et encore, pas dans son ensemble !).
595631

596632
```{python, eval = TRUE}
597633
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)
599637
ax
600638
```
601639

0 commit comments

Comments
 (0)