Skip to content

feat: add multiplot tabs to the streamlit dashboard #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
814 changes: 536 additions & 278 deletions app.py

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions plots/barplot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# filepath: c:\Users\kamat\OneDrive\Desktop\Work\UIUC\Research\maidr\maidr_streamlit\plots\barplot.py
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
from plots.utils import set_theme, color_palettes

def create_barplot(input_barplot_color, theme):
"""Create a bar plot based on input parameters"""
color = color_palettes[input_barplot_color]
categories = ["Category A", "Category B", "Category C", "Category D", "Category E"]
values = np.random.randint(10, 100, size=5)

fig, ax = plt.subplots(figsize=(10, 6))
set_theme(fig, ax, theme)
sns.barplot(x=categories, y=values, ax=ax, color=color)
ax.set_title("Plot of Categories")
ax.set_xlabel("Categories")
ax.set_ylabel("Values")

return ax

def create_custom_barplot(df, var, color, theme):
"""Create a bar plot from user data"""
if not var or df is None:
return None

fig, ax = plt.subplots(figsize=(10, 6))
set_theme(fig, ax, theme)
sns.countplot(data=df, x=var, color=color, ax=ax)
ax.set_title(f"{var}")
ax.set_xlabel(var.replace("_", " ").title())
ax.set_ylabel("Count")

return ax
54 changes: 54 additions & 0 deletions plots/boxplot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# filepath: c:\Users\kamat\OneDrive\Desktop\Work\UIUC\Research\maidr\maidr_streamlit\plots\boxplot.py
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
from plots.utils import set_theme, color_palettes

def create_boxplot(input_boxplot_type, input_boxplot_color, theme):
"""Create a box plot based on input parameters"""
boxplot_type = input_boxplot_type
color = color_palettes[input_boxplot_color]

# Generate data based on the selected box plot type
if boxplot_type == "Positively Skewed with Outliers":
data = np.random.lognormal(mean=0, sigma=0.5, size=1000)
elif boxplot_type == "Negatively Skewed with Outliers":
data = -np.random.lognormal(mean=0, sigma=0.5, size=1000)
elif boxplot_type == "Symmetric with Outliers":
data = np.random.normal(loc=0, scale=1, size=1000)
elif boxplot_type == "Symmetric without Outliers":
data = np.random.normal(loc=0, scale=1, size=1000)
data = data[(data > -1.5) & (data < 1.5)] # Strict range to avoid outliers
else:
data = np.random.normal(loc=0, scale=1, size=1000)

# Create the plot using matplotlib
fig, ax = plt.subplots(figsize=(10, 6))
set_theme(fig, ax, theme)
sns.boxplot(x=data, ax=ax, color=color) # Horizontal box plot
ax.set_title(f"{boxplot_type}")
ax.set_xlabel("Value")

return ax

def create_custom_boxplot(df, var_x, var_y, color, theme):
"""Create a box plot from user data"""
if df is None:
return None

fig, ax = plt.subplots(figsize=(10, 6))
set_theme(fig, ax, theme)

if var_x and var_y:
sns.boxplot(x=var_y, y=var_x, data=df, palette=[color], ax=ax)
ax.set_title(f"{var_x} grouped by {var_y}")
ax.set_xlabel(var_y.replace("_", " ").title())
ax.set_ylabel(var_x.replace("_", " ").title())
elif var_x:
sns.boxplot(y=df[var_x], color=color, ax=ax)
ax.set_title(f"{var_x}")
ax.set_ylabel(var_x.replace("_", " ").title())
else:
return None

return ax
51 changes: 51 additions & 0 deletions plots/heatmap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# filepath: c:\Users\kamat\OneDrive\Desktop\Work\UIUC\Research\maidr\maidr_streamlit\plots\heatmap.py
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import pandas as pd
from plots.utils import set_theme

def create_heatmap(input_heatmap_type, theme):
"""Create a heatmap based on input parameters"""
heatmap_type = input_heatmap_type

if heatmap_type == "Random":
data = np.random.rand(5, 5) # Reduced size
elif heatmap_type == "Correlated":
data = np.random.multivariate_normal(
[0] * 5, np.eye(5), size=5
) # Reduced size
elif heatmap_type == "Checkerboard":
data = np.indices((5, 5)).sum(axis=0) % 2 # Reduced size
else:
data = np.random.rand(5, 5)

fig, ax = plt.subplots(figsize=(10, 8))
set_theme(fig, ax, theme)
sns.heatmap(data, ax=ax, cmap="YlGnBu", annot=True, fmt=".2f")
ax.set_title(f"{heatmap_type}")

return ax

def create_custom_heatmap(df, var_x, var_y, var_value, colorscale, theme):
"""Create a heatmap from user data"""
if not var_x or not var_y or df is None:
return None

fig, ax = plt.subplots(figsize=(10, 8))
set_theme(fig, ax, theme)

# Check if both variables are categorical and a value variable is provided
if var_value:
# Create a pivot table
pivot_table = pd.pivot_table(df, values=var_value, index=var_y, columns=var_x, aggfunc='mean')
else:
# If no value variable, use crosstab for frequency counts
pivot_table = pd.crosstab(df[var_y], df[var_x], normalize='all')

sns.heatmap(pivot_table, ax=ax, cmap=colorscale, annot=True, fmt=".2f")
ax.set_title(f"Heatmap of {var_y} vs {var_x}")
ax.set_xlabel(var_x.replace("_", " ").title())
ax.set_ylabel(var_y.replace("_", " ").title())

return ax
61 changes: 61 additions & 0 deletions plots/histogram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# filepath: c:\Users\kamat\OneDrive\Desktop\Work\UIUC\Research\maidr\maidr_streamlit\plots\histogram.py
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
from plots.utils import set_theme, color_palettes

def create_histogram(input_distribution_type, input_hist_color, theme):
"""Create a histogram based on input parameters"""
distribution_type = input_distribution_type
color = color_palettes[input_hist_color]

# Generate data based on the selected distribution
if distribution_type == "Normal Distribution":
data = np.random.normal(size=1000)
elif distribution_type == "Positively Skewed":
data = np.random.exponential(scale=3, size=1000)
elif distribution_type == "Negatively Skewed":
data = -np.random.exponential(scale=1.5, size=1000)
elif distribution_type == "Unimodal Distribution":
data = np.random.normal(loc=0, scale=2.5, size=1000)
elif distribution_type == "Bimodal Distribution":
data = np.concatenate(
[
np.random.normal(-2, 0.5, size=500),
np.random.normal(2, 0.5, size=500),
]
)
elif distribution_type == "Multimodal Distribution":
data = np.concatenate(
[
np.random.normal(-2, 0.5, size=300),
np.random.normal(2, 0.5, size=300),
np.random.normal(5, 0.5, size=400),
]
)
else:
data = np.random.normal(size=1000)

# Create the plot using matplotlib
fig, ax = plt.subplots(figsize=(10, 6))
set_theme(fig, ax, theme)
sns.histplot(data, kde=True, bins=20, color=color, edgecolor="white", ax=ax)
ax.set_title(f"{distribution_type}")
ax.set_xlabel("Value")
ax.set_ylabel("Frequency")

return ax

def create_custom_histogram(df, var, color, theme):
"""Create a histogram from user data"""
if not var or df is None:
return None

fig, ax = plt.subplots(figsize=(10, 6))
set_theme(fig, ax, theme)
sns.histplot(data=df, x=var, kde=True, color=color, ax=ax)
ax.set_title(f"{var}")
ax.set_xlabel(var.replace("_", " ").title())
ax.set_ylabel("Count")

return ax
45 changes: 45 additions & 0 deletions plots/lineplot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# filepath: c:\Users\kamat\OneDrive\Desktop\Work\UIUC\Research\maidr\maidr_streamlit\plots\lineplot.py
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
from plots.utils import set_theme, color_palettes

def create_lineplot(input_lineplot_type, input_lineplot_color, theme):
"""Create a line plot based on input parameters"""
lineplot_type = input_lineplot_type
color = color_palettes[input_lineplot_color]

x = np.linspace(0, 10, 20) # Reduced number of points
if lineplot_type == "Linear Trend":
y = 2 * x + 1 + np.random.normal(0, 1, 20)
elif lineplot_type == "Exponential Growth":
y = np.exp(0.5 * x) + np.random.normal(0, 1, 20)
elif lineplot_type == "Sinusoidal Pattern":
y = 5 * np.sin(x) + np.random.normal(0, 0.5, 20)
elif lineplot_type == "Random Walk":
y = np.cumsum(np.random.normal(0, 1, 20))
else:
y = x + np.random.normal(0, 1, 20)

fig, ax = plt.subplots(figsize=(10, 6))
set_theme(fig, ax, theme)
sns.lineplot(x=x, y=y, ax=ax, color=color)
ax.set_title(f"{lineplot_type}")
ax.set_xlabel("X")
ax.set_ylabel("Y")

return ax

def create_custom_lineplot(df, var_x, var_y, color, theme):
"""Create a line plot from user data"""
if not var_x or not var_y or df is None:
return None

fig, ax = plt.subplots(figsize=(10, 6))
set_theme(fig, ax, theme)
sns.lineplot(data=df, x=var_x, y=var_y, color=color, ax=ax)
ax.set_title(f"{var_y} vs {var_x}")
ax.set_xlabel(var_x.replace("_", " ").title())
ax.set_ylabel(var_y.replace("_", " ").title())

return ax
Loading