Rename visualizer.py to visualization.py
Browse files- visualization.py +41 -0
- visualizer.py +0 -47
visualization.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import matplotlib.pyplot as plt
|
| 2 |
+
import seaborn as sns
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
class VisualizationSelector:
|
| 7 |
+
def select_visualizations(self, data):
|
| 8 |
+
visualizations = []
|
| 9 |
+
|
| 10 |
+
# Histogram for numerical columns
|
| 11 |
+
numeric_columns = data.select_dtypes(include=[np.number]).columns
|
| 12 |
+
for column in numeric_columns:
|
| 13 |
+
fig, ax = plt.subplots()
|
| 14 |
+
sns.histplot(data[column], kde=True, ax=ax)
|
| 15 |
+
ax.set_title(f'Distribution of {column}')
|
| 16 |
+
visualizations.append(fig)
|
| 17 |
+
|
| 18 |
+
# Correlation heatmap
|
| 19 |
+
if len(numeric_columns) > 1:
|
| 20 |
+
fig, ax = plt.subplots(figsize=(10, 8))
|
| 21 |
+
sns.heatmap(data[numeric_columns].corr(), annot=True, cmap='coolwarm', ax=ax)
|
| 22 |
+
ax.set_title('Correlation Heatmap')
|
| 23 |
+
visualizations.append(fig)
|
| 24 |
+
|
| 25 |
+
# Scatter plot matrix
|
| 26 |
+
if len(numeric_columns) > 1:
|
| 27 |
+
fig = sns.pairplot(data[numeric_columns])
|
| 28 |
+
fig.fig.suptitle('Scatter Plot Matrix', y=1.02)
|
| 29 |
+
visualizations.append(fig)
|
| 30 |
+
|
| 31 |
+
# Box plots for categorical vs numerical
|
| 32 |
+
categorical_columns = data.select_dtypes(include=['object']).columns
|
| 33 |
+
for cat_col in categorical_columns:
|
| 34 |
+
for num_col in numeric_columns:
|
| 35 |
+
fig, ax = plt.subplots()
|
| 36 |
+
sns.boxplot(x=cat_col, y=num_col, data=data, ax=ax)
|
| 37 |
+
ax.set_title(f'{cat_col} vs {num_col}')
|
| 38 |
+
ax.set_xticklabels(ax.get_xticklabels(), rotation=45, ha='right')
|
| 39 |
+
visualizations.append(fig)
|
| 40 |
+
|
| 41 |
+
return visualizations
|
visualizer.py
DELETED
|
@@ -1,47 +0,0 @@
|
|
| 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|