Update visualizer.py
Browse files- visualizer.py +44 -11
visualizer.py
CHANGED
@@ -1,14 +1,47 @@
|
|
|
|
1 |
import plotly.express as px
|
|
|
2 |
|
3 |
class Visualizer:
|
4 |
-
def
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
import plotly.express as px
|
3 |
+
import plotly.graph_objects as go
|
4 |
|
5 |
class Visualizer:
|
6 |
+
def create_visualizations(self, df):
|
7 |
+
chart_type = st.selectbox("Select chart type",
|
8 |
+
["Scatter", "Line", "Bar", "Histogram", "Box Plot", "Heatmap", "Pie Chart", "3D Scatter"])
|
9 |
+
|
10 |
+
if chart_type in ["Scatter", "Line", "Bar"]:
|
11 |
+
x_axis = st.selectbox("Select X-axis", df.columns)
|
12 |
+
y_axis = st.selectbox("Select Y-axis", df.columns)
|
13 |
+
color = st.selectbox("Select color (optional)", ["None"] + df.columns.tolist())
|
14 |
+
|
15 |
+
if chart_type == "Scatter":
|
16 |
+
fig = px.scatter(df, x=x_axis, y=y_axis, color=None if color == "None" else color)
|
17 |
+
elif chart_type == "Line":
|
18 |
+
fig = px.line(df, x=x_axis, y=y_axis, color=None if color == "None" else color)
|
19 |
+
else: # Bar
|
20 |
+
fig = px.bar(df, x=x_axis, y=y_axis, color=None if color == "None" else color)
|
21 |
+
|
22 |
+
elif chart_type == "Histogram":
|
23 |
+
column = st.selectbox("Select column", df.columns)
|
24 |
+
fig = px.histogram(df, x=column)
|
25 |
+
|
26 |
+
elif chart_type == "Box Plot":
|
27 |
+
y_axis = st.selectbox("Select Y-axis", df.columns)
|
28 |
+
x_axis = st.selectbox("Select X-axis (optional)", ["None"] + df.columns.tolist())
|
29 |
+
fig = px.box(df, y=y_axis, x=None if x_axis == "None" else x_axis)
|
30 |
+
|
31 |
+
elif chart_type == "Heatmap":
|
32 |
+
corr_matrix = df.corr()
|
33 |
+
fig = px.imshow(corr_matrix, color_continuous_scale='RdBu_r')
|
34 |
+
|
35 |
+
elif chart_type == "Pie Chart":
|
36 |
+
values = st.selectbox("Select values", df.columns)
|
37 |
+
names = st.selectbox("Select names", df.columns)
|
38 |
+
fig = px.pie(df, values=values, names=names)
|
39 |
+
|
40 |
+
elif chart_type == "3D Scatter":
|
41 |
+
x_axis = st.selectbox("Select X-axis", df.columns)
|
42 |
+
y_axis = st.selectbox("Select Y-axis", df.columns)
|
43 |
+
z_axis = st.selectbox("Select Z-axis", df.columns)
|
44 |
+
color = st.selectbox("Select color (optional)", ["None"] + df.columns.tolist())
|
45 |
+
fig = px.scatter_3d(df, x=x_axis, y=y_axis, z=z_axis, color=None if color == "None" else color)
|
46 |
+
|
47 |
+
st.plotly_chart(fig)
|