@@ -166,7 +166,7 @@ En l'occurrence, on peut utiliser `plotly` pour tenir compte de la population:
166
166
167
167
``` {python, include = TRUE, echo=TRUE}
168
168
import plotly
169
- import plotly.graph_objects as go
169
+ import plotly.graph_objects as pgo
170
170
import pandas as pd
171
171
import geopandas as gpd
172
172
@@ -195,20 +195,31 @@ colors = ['#FF0000', '#0000FF']
195
195
df['color'] = df['winner'].replace(color_dict)
196
196
df['size'] = df['CENSUS_2010_POP']/6000
197
197
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(
205
216
marker = dict(
206
217
opacity=0.5,
207
218
line_color='rgb(40,40,40)',
208
219
line_width=0.5,
209
220
sizemode = 'area'
210
221
)
211
- ) )
222
+ )
212
223
213
224
fig_plotly.update_layout(
214
225
title_text = "Reproduction of the \"Acres don't vote, people do\" map <br>(Click legend to toggle traces)",
0 commit comments