Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +58 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
import seaborn as sns
|
| 5 |
+
import matplotlib.pyplot as plt
|
| 6 |
+
# Apply the default theme and activate color codes
|
| 7 |
+
sns.set_theme()
|
| 8 |
+
sns.set(color_codes=True)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
import streamlit as st
|
| 12 |
+
import altair as alt
|
| 13 |
+
import seaborn as sns
|
| 14 |
+
import pandas as pd
|
| 15 |
+
|
| 16 |
+
st.title("🐧 Palmer Penguins Explorer")
|
| 17 |
+
|
| 18 |
+
# 载入数据
|
| 19 |
+
penguins = sns.load_dataset("penguins")
|
| 20 |
+
penguins_clean = penguins.dropna(subset=[
|
| 21 |
+
"bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g", "species"
|
| 22 |
+
])
|
| 23 |
+
|
| 24 |
+
# 侧边栏选择
|
| 25 |
+
x_col = st.sidebar.selectbox("X 轴", ["bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"])
|
| 26 |
+
y_col = st.sidebar.selectbox("Y 轴", ["flipper_length_mm", "bill_length_mm", "bill_depth_mm", "body_mass_g"])
|
| 27 |
+
size_col = st.sidebar.selectbox("点大小", ["body_mass_g", "flipper_length_mm", "bill_length_mm"])
|
| 28 |
+
color_col = st.sidebar.selectbox("颜色分组", ["species", "island", "sex"])
|
| 29 |
+
|
| 30 |
+
st.write(f"**X 轴**:`{x_col}`,**Y 轴**:`{y_col}`,**大小**:`{size_col}`,**颜色**:`{color_col}`")
|
| 31 |
+
|
| 32 |
+
chart = (
|
| 33 |
+
alt.Chart(penguins_clean)
|
| 34 |
+
.mark_point(filled=True)
|
| 35 |
+
.encode(
|
| 36 |
+
alt.X(x_col, title=x_col.replace("_", " ").title()),
|
| 37 |
+
alt.Y(y_col, title=y_col.replace("_", " ").title()),
|
| 38 |
+
alt.Size(size_col, title=size_col.replace("_", " ").title(), scale=alt.Scale(range=[20, 300])),
|
| 39 |
+
alt.Color(color_col, title=color_col.replace("_", " ").title()),
|
| 40 |
+
alt.OpacityValue(0.7),
|
| 41 |
+
tooltip=[
|
| 42 |
+
alt.Tooltip("species", title="Species"),
|
| 43 |
+
alt.Tooltip("island", title="Island"),
|
| 44 |
+
alt.Tooltip("sex", title="Sex"),
|
| 45 |
+
alt.Tooltip("bill_length_mm", title="Bill Length (mm)"),
|
| 46 |
+
alt.Tooltip("bill_depth_mm", title="Bill Depth (mm)"),
|
| 47 |
+
alt.Tooltip("flipper_length_mm", title="Flipper Length (mm)"),
|
| 48 |
+
alt.Tooltip("body_mass_g", title="Body Mass (g)"),
|
| 49 |
+
],
|
| 50 |
+
)
|
| 51 |
+
.properties(width=750, height=460, title="Palmer Penguins — Interactive Scatter")
|
| 52 |
+
.interactive()
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
st.altair_chart(chart, use_container_width=True)
|
| 56 |
+
|
| 57 |
+
st.subheader("原始数据(清洗后)")
|
| 58 |
+
st.dataframe(penguins_clean)
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit== 1.37.1
|
| 2 |
+
pandas == 2.2.3
|
| 3 |
+
seaborn == 0.13.2
|
| 4 |
+
numpy == 1.26.4
|