Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import seaborn as sns
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
|
5 |
+
# Load datasets names
|
6 |
+
dataset_names = sns.get_dataset_names()
|
7 |
+
|
8 |
+
# Sidebar for user inputs
|
9 |
+
st.sidebar.header('User Input Features')
|
10 |
+
selected_dataset = st.sidebar.selectbox('Select a dataset', dataset_names)
|
11 |
+
|
12 |
+
# Load the selected dataset
|
13 |
+
data = sns.load_dataset(selected_dataset)
|
14 |
+
|
15 |
+
# Select plot
|
16 |
+
plot_types = ['scatterplot', 'lineplot', 'histplot', 'boxplot', 'violinplot',
|
17 |
+
'barplot', 'countplot', 'pairplot', 'heatmap', 'jointplot', 'kdeplot']
|
18 |
+
plot_type = st.sidebar.selectbox('Select the type of plot', plot_types)
|
19 |
+
|
20 |
+
# Options for different plots
|
21 |
+
if plot_type in ['scatterplot', 'lineplot', 'barplot', 'countplot']:
|
22 |
+
x_var = st.sidebar.selectbox('Choose X variable', data.columns)
|
23 |
+
y_var = st.sidebar.selectbox('Choose Y variable', data.columns if plot_type != 'countplot' else ['None'])
|
24 |
+
hue_var = st.sidebar.selectbox('Hue (optional)', ['None'] + list(data.columns), index=0)
|
25 |
+
elif plot_type in ['histplot', 'boxplot', 'violinplot', 'kdeplot']:
|
26 |
+
x_var = st.sidebar.selectbox('Choose variable', data.columns)
|
27 |
+
hue_var = st.sidebar.selectbox('Hue (optional)', ['None'] + list(data.columns), index=0)
|
28 |
+
elif plot_type == 'jointplot':
|
29 |
+
x_var = st.sidebar.selectbox('Choose X variable', data.columns)
|
30 |
+
y_var = st.sidebar.selectbox('Choose Y variable', data.columns)
|
31 |
+
elif plot_type == 'pairplot':
|
32 |
+
hue_var = st.sidebar.selectbox('Hue (optional for pairplot)', ['None'] + list(data.columns), index=0)
|
33 |
+
elif plot_type == 'heatmap':
|
34 |
+
# Typically used for correlation matrices or pivot tables
|
35 |
+
st.write("Heatmap will display correlation matrix for numerical data.")
|
36 |
+
|
37 |
+
# Handle hue
|
38 |
+
hue = None if hue_var == 'None' else hue_var
|
39 |
+
|
40 |
+
# Main area
|
41 |
+
st.title('Seaborn Plot Viewer')
|
42 |
+
|
43 |
+
# Generate plot based on the type
|
44 |
+
fig, ax = plt.subplots()
|
45 |
+
|
46 |
+
if plot_type == 'scatterplot':
|
47 |
+
sns.scatterplot(data=data, x=x_var, y=y_var, hue=hue, ax=ax)
|
48 |
+
elif plot_type == 'lineplot':
|
49 |
+
sns.lineplot(data=data, x=x_var, y=y_var, hue=hue, ax=ax)
|
50 |
+
elif plot_type == 'histplot':
|
51 |
+
sns.histplot(data=data, x=x_var, hue=hue, ax=ax)
|
52 |
+
elif plot_type == 'boxplot':
|
53 |
+
sns.boxplot(data=data, x=x_var, hue=hue, ax=ax)
|
54 |
+
elif plot_type == 'violinplot':
|
55 |
+
sns.violinplot(data=data, x=x_var, hue=hue, ax=ax)
|
56 |
+
elif plot_type == 'barplot':
|
57 |
+
sns.barplot(data=data, x=x_var, y=y_var, hue=hue, ax=ax)
|
58 |
+
elif plot_type == 'countplot':
|
59 |
+
sns.countplot(data=data, x=x_var, hue=hue, ax=ax)
|
60 |
+
elif plot_type == 'pairplot':
|
61 |
+
if hue:
|
62 |
+
sns.pairplot(data=data, hue=hue)
|
63 |
+
else:
|
64 |
+
sns.pairplot(data=data)
|
65 |
+
st.pyplot()
|
66 |
+
st.stop()
|
67 |
+
elif plot_type == 'heatmap':
|
68 |
+
corr = data.corr()
|
69 |
+
sns.heatmap(corr, annot=True, cmap='coolwarm', ax=ax)
|
70 |
+
elif plot_type == 'jointplot':
|
71 |
+
sns.jointplot(data=data, x=x_var, y=y_var, kind='scatter')
|
72 |
+
st.pyplot()
|
73 |
+
st.stop()
|
74 |
+
elif plot_type == 'kdeplot':
|
75 |
+
sns.kdeplot(data=data, x=x_var, hue=hue, ax=ax)
|
76 |
+
|
77 |
+
st.pyplot(fig)
|