diff --git a/content/course/modelisation/0_preprocessing.Rmd b/content/course/modelisation/0_preprocessing.Rmd index a7a068602..c9e00813c 100644 --- a/content/course/modelisation/0_preprocessing.Rmd +++ b/content/course/modelisation/0_preprocessing.Rmd @@ -192,24 +192,23 @@ colors = ['#FF0000', '#0000FF'] ``` ```{python, include = TRUE, echo=TRUE} -fig_plotly = go.Figure() - -for i in range(2): - tempdf = df.loc[df['winner'].astype(str) == limits[i]] - fig_plotly.add_trace(go.Scattergeo( - locationmode = 'USA-states', - lon = tempdf['lon'], - lat = tempdf['lat'], - text = tempdf['text'], - name = 'Winner: {}'.format(limits[i]), - marker = dict( - size = tempdf['CENSUS_2010_POP']/6000, - color = colors[i], - opacity=0.5, - line_color='rgb(40,40,40)', - line_width=0.5, - sizemode = 'area' - ))) +df['color'] = df['winner'].replace(color_dict) +df['size'] = df['CENSUS_2010_POP']/6000 + +fig_plotly = go.Figure(data=go.Scattergeo( + locationmode = 'USA-states', + lon=df["lon"], lat=df["lat"], + text = df["text"], + mode = 'markers', + marker_color = df["color"], + marker_size = df['size'], + marker = dict( + opacity=0.5, + line_color='rgb(40,40,40)', + line_width=0.5, + sizemode = 'area' + ) + )) fig_plotly.update_layout( title_text = "Reproduction of the \"Acres don't vote, people do\" map
(Click legend to toggle traces)", @@ -219,7 +218,6 @@ fig_plotly.update_layout( landcolor = 'rgb(217, 217, 217)', ) ) - ```