Spaces:
Running
Running
Create visuals.py
Browse files- visuals.py +44 -0
visuals.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# visuals.py
|
2 |
+
import plotly.express as px
|
3 |
+
import streamlit as st
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
def render_summary(df: pd.DataFrame):
|
7 |
+
st.header("Summary Statistics")
|
8 |
+
col1, col2, col3 = st.columns(3)
|
9 |
+
with col1:
|
10 |
+
st.metric("Total Asteroids", len(df))
|
11 |
+
with col2:
|
12 |
+
hazardous_count = df['is_hazardous'].sum()
|
13 |
+
st.metric("Potentially Hazardous", f"{hazardous_count} ({hazardous_count/len(df)*100:.1f}%)")
|
14 |
+
with col3:
|
15 |
+
st.metric("Avg. Size", f"{df['avg_diameter_km'].mean():.2f} km")
|
16 |
+
|
17 |
+
def render_visualizations(df: pd.DataFrame):
|
18 |
+
st.header("Visualizations")
|
19 |
+
viz_tab1, viz_tab2 = st.tabs(["Size Distribution", "Miss Distance"])
|
20 |
+
|
21 |
+
with viz_tab1:
|
22 |
+
fig1 = px.histogram(
|
23 |
+
df, x="avg_diameter_km", color="is_hazardous",
|
24 |
+
title="Size Distribution of Near-Earth Objects",
|
25 |
+
labels={"avg_diameter_km": "Average Diameter (km)", "is_hazardous": "Potentially Hazardous"},
|
26 |
+
color_discrete_map={True: "red", False: "green"}
|
27 |
+
)
|
28 |
+
st.plotly_chart(fig1, use_container_width=True)
|
29 |
+
|
30 |
+
with viz_tab2:
|
31 |
+
fig2 = px.scatter(
|
32 |
+
df, x="miss_distance_km", y="avg_diameter_km", color="is_hazardous",
|
33 |
+
size="relative_velocity_kph", hover_name="name",
|
34 |
+
title="Miss Distance vs. Size (with velocity)",
|
35 |
+
labels={
|
36 |
+
"miss_distance_km": "Miss Distance (km)",
|
37 |
+
"avg_diameter_km": "Average Diameter (km)",
|
38 |
+
"is_hazardous": "Potentially Hazardous",
|
39 |
+
"relative_velocity_kph": "Velocity (km/h)"
|
40 |
+
},
|
41 |
+
color_discrete_map={True: "red", False: "green"}
|
42 |
+
)
|
43 |
+
fig2.update_layout(xaxis_type="log")
|
44 |
+
st.plotly_chart(fig2, use_container_width=True)
|