fig = go.Figure(go.Scattergeo()) fig.update_geos( visible=False, resolution=110, scope="usa", showcountries=True, countrycolor="Black", showsubunits=True, subunitcolor="Blue" ) fig.update_layout(height=300, margin={"r":0,"t":0,"l":0,"b":0}) fig.show() Use this to build an electoral Map, with a color grading for which state have % of vote for the party, use the red / blue gradient for the party, Highlight the swing state
To upload files, please first save the app
import streamlit as st
import plotly.graph_objects as go
import plotly.express as px
import pandas as pd
data = {
'usa_state_code': ['CA', 'TX', 'FL', 'NY', 'IL', 'OH', 'PA'],
'state': states,
'percent_republican': percentages,
'percent_democrat': [100 - p for p in percentages]
}
df = pd.DataFrame(data)
fix = px.choropleth(df,
locations = 'usa_state_code',
locationmode = 'USA-states',
color = 'percent_republican',
hover_name = 'state',
hove_data = 'percent_republican', 'percent_democrat',
range_color = [10, 90],
color_continuous_scale = 'armyrose'
)
# Streamlit app structure
st.title('Electoral Vote Map')
st.plotly_chart(fig)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?