-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
68 lines (58 loc) · 1.62 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import streamlit as st
import plotly.express as px
import pandas as pd
st.set_page_config(layout="wide")
st.title("2024 Olympic Medlists Birth Locations")
df = pd.read_csv('2024_medalists_all.csv')
df_filtered = df.dropna(subset=['lat', 'lon'])
medal_colors = {
'gold': '#FFD700',
'silver':'#C0C0C0',
'bronze': '#CD7F32'
}
df_filtered['representing_country'] = "Representing: " + df_filtered["country_medal"]
print(df_filtered.head())
fig = px.scatter_geo(
df_filtered,
lat="lat",
lon="lon",
hover_name='medalist_name',
hover_data={'medal':True, 'lat': False, 'lon': False, 'place_of_birth': True, 'representing_country': True, 'event_name': True},
color='medal',
color_discrete_map=medal_colors,
title="2024 Olympic Medlists Birth Locations",
projection="natural earth",
template="plotly_dark"
)
# Customize hover template
fig.update_traces(
hovertemplate=(
"<b>%{hovertext}</b><br><br>" +
"Medal: %{customdata[0]}<br>" +
"Birth Place: %{customdata[3]}<br>" +
"Representing: %{customdata[4]}<br>" +
"Event: %{customdata[5]}<br>" +
"<extra></extra>"
)
)
fig.update_geos(
showcoastlines=True,
coastlinecolor='white',
showland=True,
landcolor="black",
showocean=True,
oceancolor="darkgrey",
showlakes=True,
lakecolor="darkgrey",
showcountries=True,
countrycolor="white",
bgcolor='black'
)
fig.update_layout(
height=700,
margin={"r": 0, "t": 50, "l": 0, "b":0},
plot_bgcolor = 'black',
paper_bgcolor='black',
font_color="white",
)
st.plotly_chart(fig, use_container_width=True)