Ailee52 commited on
Commit
92bfe16
·
verified ·
1 Parent(s): 0f268ff

Upload 2 files

Browse files
Files changed (2) hide show
  1. Requirements.txt.txt +4 -0
  2. app.py +85 -0
Requirements.txt.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit==1.35.0
2
+ pandas==2.2.2
3
+ seaborn==0.13.2
4
+ matplotlib==3.8.4
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import pandas as pd
4
+
5
+
6
+ import seaborn as sns
7
+ import matplotlib.pyplot as plt
8
+
9
+ # Apply the default theme and activate color codes
10
+ sns.set_theme()
11
+ sns.set(color_codes=True)
12
+
13
+
14
+ ################### import dataset
15
+ penguins = sns.load_dataset("penguins")
16
+
17
+ ########### set the title and subtitle
18
+ st.title("Differences between penguins")
19
+
20
+ st.subheader("My flipper is longer!!!")
21
+
22
+ ########## we add image
23
+ st.image("https://raw.githubusercontent.com/allisonhorst/palmerpenguins/main/man/figures/lter_penguins.png")
24
+
25
+ ############## we create filters for our interactive plot
26
+ with st.sidebar:
27
+ st.subheader("Filters")
28
+
29
+ all_species = sorted(penguins["species"].dropna().unique().tolist())
30
+ selected_species = st.multiselect(
31
+ "Species to show",
32
+ options=all_species,
33
+ default=all_species,
34
+ )
35
+
36
+ feature_options = {
37
+ "Flipper length (mm)": "flipper_length_mm",
38
+ "Bill length (mm)": "bill_length_mm",
39
+ "Bill depth (mm)": "bill_depth_mm",
40
+ "Body mass (g)": "body_mass_g",
41
+ }
42
+ feature_label = st.selectbox("Feature (x-axis)", list(feature_options.keys()))
43
+ x_col = feature_options[feature_label]
44
+
45
+ # KDE options
46
+ fill = st.checkbox("Shade area", value=True)
47
+ bw_adjust = st.slider("Smoothing (bw_adjust)", 0.2, 2.0, 1.0, 0.1)
48
+ common_norm = st.checkbox("Normalize across species", value=False)
49
+
50
+ if not selected_species:
51
+ st.info("Select at least one species to display the plot.")
52
+ else:
53
+ data = penguins[penguins["species"].isin(selected_species)].dropna(subset=[x_col])
54
+
55
+ g = sns.displot(
56
+ data=data,
57
+ x=x_col,
58
+ kind="kde",
59
+ hue="species",
60
+ fill=fill,
61
+ bw_adjust=bw_adjust,
62
+ common_norm=common_norm,
63
+ height=4,
64
+ aspect=1.6,
65
+ )
66
+ fig = g.fig if hasattr(g, "fig") else g.figure
67
+ st.pyplot(fig)
68
+ plt.close(fig)
69
+
70
+ ######## add button to save image
71
+ from io import BytesIO
72
+
73
+ buf = BytesIO()
74
+ fig.savefig(buf, format="png", dpi=200, bbox_inches="tight")
75
+ buf.seek(0)
76
+ st.download_button(
77
+ "Save image",
78
+ data=buf,
79
+ file_name=f"penguins_{x_col}.png",
80
+ mime="image/png",
81
+ )
82
+
83
+ ########### Footer
84
+ st.caption("Developed for SDS M1 course.")
85
+