Skip to content

Commit 85565d5

Browse files
committed
reformat
1 parent 9ace7b9 commit 85565d5

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

content/course/modelisation/0_preprocessing.Rmd

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ En l'occurrence, on peut utiliser `plotly` pour tenir compte de la population:
166166

167167
```{python, include = TRUE, echo=TRUE}
168168
import plotly
169-
import plotly.graph_objects as go
169+
import plotly.graph_objects as pgo
170170
import pandas as pd
171171
import geopandas as gpd
172172
@@ -195,20 +195,31 @@ colors = ['#FF0000', '#0000FF']
195195
df['color'] = df['winner'].replace(color_dict)
196196
df['size'] = df['CENSUS_2010_POP']/6000
197197
198-
fig_plotly = go.Figure(data=go.Scattergeo(
199-
locationmode = 'USA-states',
200-
lon=df["lon"], lat=df["lat"],
201-
text = df["text"],
202-
mode = 'markers',
203-
marker_color = df["color"],
204-
marker_size = df['size'],
198+
df['color'] = df['winner'].replace(color_dict)
199+
df['size'] = df['CENSUS_2010_POP']/6000
200+
df['text'] = df["county_name"] + '<br>Population ' + (df['CENSUS_2010_POP']/1e3).astype(str)+' thousands'
201+
202+
fig_plotly = pgo.Figure(
203+
data=pgo.Scattergeo(
204+
locationmode = 'USA-states',
205+
lon=df["lon"], lat=df["lat"],
206+
text = df["text"],
207+
mode = 'markers',
208+
marker_color = df["color"],
209+
marker_size = df['size']
210+
)
211+
)
212+
```
213+
214+
```{python, include = TRUE, echo=TRUE}
215+
fig_plotly.update_traces(
205216
marker = dict(
206217
opacity=0.5,
207218
line_color='rgb(40,40,40)',
208219
line_width=0.5,
209220
sizemode = 'area'
210221
)
211-
))
222+
)
212223
213224
fig_plotly.update_layout(
214225
title_text = "Reproduction of the \"Acres don't vote, people do\" map <br>(Click legend to toggle traces)",

0 commit comments

Comments
 (0)