Create a streamlit app with a 3D visualization of the US. i want each city / state to have a height based on a list of value. This is to see the distribution of people that vote for trump / harris
Drop files here
or click to upload
import streamlit as st
import pandas as pd
import numpy as np
import plotly.graph_objects as go
# Sample data: Replace this with your actual data
states = ['California', 'Texas', 'Florida', 'New York', 'Illinois']
vote_counts_trump = [10, 20, 15, 5, 8]
vote_counts_harris = [12, 18, 10, 6, 11]
# Create a DataFrame
data = pd.DataFrame({
'State': states,
'Trump Votes': vote_counts_trump,
'Harris Votes': vote_counts_harris
})
# Calculate heights for 3D bars
data['Total Votes'] = data['Trump Votes'] + data['Harris Votes']
st.title('3D Visualization of Voter Distribution')
# Create 3D bar chart
fig = go.Figure()
# Add Trump votes
fig.add_trace(go.Bar(
x=data['State'],
y=data['Trump Votes'],
z=[0] * len(data),
name='Trump Votes',
marker=dict(color='blue')
))
# Add Harris votes
fig.add_trace(go.Bar(
x=data['State'],
y=data['Harris Votes'],
z=data['Trump Votes'].tolist(),
name='Harris Votes',
marker=dict(color='red')
))
# Add layout details
fig.update_layout(
scene=dict(
xaxis_title='States',
yaxis_title='Votes',
zaxis_title='Vote Counts'
),
title='3D Voter Distribution by State'
)
# Display the figure
st.plotly_chart(fig)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?