Skip to content

Commit

Permalink
Update 3_๐Ÿ“Š Visualize.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Devanik21 authored Oct 18, 2024
1 parent 6c34b64 commit 2baa4e3
Showing 1 changed file with 69 additions and 108 deletions.
177 changes: 69 additions & 108 deletions pages/3_๐Ÿ“Š Visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,149 +5,110 @@
import seaborn as sns

def show_visualize_page():
st.title("๐Ÿ“Š Mining Site Visualization")
st.write("Visualize mining site data to gain insights.")
st.title("๐ŸŒŒ Mining Site Visualization ๐ŸŒŸ")
st.write("Explore and visualize mining site data interactively!")

# Load dataset
df = pd.read_csv("space_mining_dataset.csv")

# Set seaborn style and palette for professional appearance
sns.set_style("darkgrid")
sns.set_palette("coolwarm_r")

# Select columns for visualizations
columns = df.columns.tolist()
numeric_columns = df.select_dtypes(include=['float64', 'int64']).columns.tolist()
selected_columns = st.multiselect("Select Columns to Visualize", numeric_columns, default=numeric_columns[:3])

if not selected_columns:
st.warning("Please select at least one numeric column.")
return

# Scatter Plot with user-selected columns
if len(selected_columns) >= 2:
st.write(f"### ๐Ÿงฒ {selected_columns[0]} vs. {selected_columns[1]} Composition")
# Set seaborn style and palette
sns.set_style("whitegrid")
sns.set_palette("Set2")

# Plot 1: Scatter Plot with column selection
st.write("### ๐Ÿงฒ Scatter Plot")
scatter_x = st.selectbox("Choose X-axis for Scatter Plot", df.columns, index=0)
scatter_y = st.selectbox("Choose Y-axis for Scatter Plot", df.columns, index=1)
if scatter_x and scatter_y:
st.write(f"### {scatter_x} vs. {scatter_y} Composition ๐ŸŒ€")
plt.figure(figsize=(10, 6))
sns.scatterplot(x=selected_columns[0], y=selected_columns[1], data=df, hue='Celestial Body',
sns.scatterplot(x=scatter_x, y=scatter_y, data=df, hue='Celestial Body',
palette='Spectral', s=100, edgecolor='black')
plt.title(f'{selected_columns[0]} vs. {selected_columns[1]} Composition', fontsize=16, fontweight='bold')
plt.xlabel(f'{selected_columns[0]}', fontsize=14)
plt.ylabel(f'{selected_columns[1]}', fontsize=14)
plt.title(f'{scatter_x} vs. {scatter_y} Composition', fontsize=16, fontweight='bold')
plt.xlabel(f'{scatter_x}', fontsize=14)
plt.ylabel(f'{scatter_y}', fontsize=14)
plt.grid(True)
st.pyplot(plt)

# Histogram of selected column
if len(selected_columns) >= 1:
st.write(f"### ๐Ÿญ Distribution of {selected_columns[0]}")
# Plot 2: Histogram with column selection
st.write("### ๐Ÿ“Š Histogram")
hist_col = st.selectbox("Choose a Column for Histogram", df.columns, index=0)
if hist_col:
st.write(f"### Distribution of {hist_col} ๐Ÿ“‰")
plt.figure(figsize=(10, 6))
sns.histplot(df[selected_columns[0]], kde=True, color='crimson', bins=20, edgecolor='black')
plt.title(f'Distribution of {selected_columns[0]}', fontsize=16, fontweight='bold')
plt.xlabel(f'{selected_columns[0]}', fontsize=14)
sns.histplot(df[hist_col], kde=True, color='crimson', bins=20, edgecolor='black')
plt.title(f'Distribution of {hist_col}', fontsize=16, fontweight='bold')
plt.xlabel(f'{hist_col}', fontsize=14)
plt.ylabel('Frequency', fontsize=14)
plt.grid(True)
st.pyplot(plt)

# Violin Plot
if len(selected_columns) >= 1:
st.write(f"### ๐ŸŽป {selected_columns[0]} Distribution by Celestial Body (Violin Plot)")
# Plot 3: Violin Plot with column selection
st.write("### ๐ŸŽป Violin Plot")
violin_col = st.selectbox("Choose a Column for Violin Plot", df.columns, index=0)
if violin_col:
st.write(f"### {violin_col} Distribution by Celestial Body ๐ŸŽถ")
plt.figure(figsize=(12, 6))
sns.violinplot(x='Celestial Body', y=selected_columns[0], data=df, palette='muted')
plt.title(f'{selected_columns[0]} Distribution by Celestial Body (Violin Plot)', fontsize=16, fontweight='bold')
sns.violinplot(x='Celestial Body', y=violin_col, data=df, palette='muted')
plt.title(f'{violin_col} Distribution by Celestial Body (Violin Plot)', fontsize=16, fontweight='bold')
plt.xticks(rotation=45, fontsize=12)
plt.grid(True)
st.pyplot(plt)

# FacetGrid for selected column
if len(selected_columns) >= 1:
st.write(f"### ๐Ÿช {selected_columns[0]} Distribution by Celestial Body (FacetGrid)")
g = sns.FacetGrid(df, col='Celestial Body', height=4, aspect=1.2)
g.map(sns.histplot, selected_columns[0], kde=True, bins=15, color='orange')
g.set_axis_labels(selected_columns[0], 'Frequency')
g.fig.suptitle(f'{selected_columns[0]} Distribution by Celestial Body (FacetGrid)', fontsize=16, fontweight='bold')
st.pyplot(g.fig)

# Pie Chart of Celestial Bodies
st.write("### ๐ŸŒŒ Celestial Body Distribution")
# Plot 4: Pie Chart for Celestial Body Distribution
st.write("### ๐ŸŒŒ Celestial Body Distribution (Pie Chart) ๐Ÿฐ")
body_counts = df['Celestial Body'].value_counts()
plt.figure(figsize=(8, 8))
plt.pie(body_counts, labels=body_counts.index, autopct='%1.1f%%', startangle=140,
colors=sns.color_palette("Set2"), wedgeprops={'edgecolor': 'black'})
plt.title('Celestial Body Distribution', fontsize=16, fontweight='bold')
st.pyplot(plt)

# Boxplot of Selected Columns by Celestial Body
if len(selected_columns) >= 1:
st.write(f"### ๐Ÿ’ต {selected_columns[0]} by Celestial Body (Boxplot)")
plt.figure(figsize=(12, 6))
sns.boxplot(x='Celestial Body', y=selected_columns[0], data=df, palette='rocket')
plt.xticks(rotation=45, fontsize=12)
plt.title(f'{selected_columns[0]} by Celestial Body', fontsize=16, fontweight='bold')
plt.grid(True)
st.pyplot(plt)

# Correlation Heatmap
# Plot 5: Correlation Heatmap with selected numeric columns
st.write("### ๐Ÿ”ฅ Correlation Heatmap")
numeric_df = df[selected_columns].select_dtypes(include=['float64', 'int64'])
if not numeric_df.empty:
plt.figure(figsize=(10, 8))
corr_matrix = numeric_df.corr()
mask = np.triu(np.ones_like(corr_matrix, dtype=bool)) # Mask upper triangle
sns.heatmap(corr_matrix, annot=True, cmap='coolwarm', fmt='.2f', linewidths=0.5,
cbar_kws={'shrink': 0.5}, mask=mask)
plt.title('Correlation Heatmap of Selected Features', fontsize=16, fontweight='bold')
st.pyplot(plt)
else:
st.warning("No numeric columns selected for correlation heatmap.")

# Pairplot
if len(selected_columns) > 1:
st.write("### ๐Ÿ”— Pairplot of Selected Features")
sns.pairplot(df[selected_columns], diag_kind='kde', palette='coolwarm', plot_kws={'edgecolor': 'black'})
selected_columns = st.multiselect("Choose Columns for Correlation Heatmap", df.columns)
if selected_columns:
numeric_df = df[selected_columns].select_dtypes(include=['float64', 'int64'])
if not numeric_df.empty:
plt.figure(figsize=(10, 8))
corr_matrix = numeric_df.corr()
sns.heatmap(corr_matrix, annot=True, cmap='coolwarm', fmt='.2f', linewidths=0.5,
cbar_kws={'shrink': 0.5})
plt.title('Correlation Heatmap of Selected Features', fontsize=16, fontweight='bold')
st.pyplot(plt)
else:
st.warning("Please select numeric columns for the heatmap.")

# Plot 6: Pairplot with selected columns
st.write("### ๐Ÿ”— Pairplot")
pairplot_columns = st.multiselect("Choose Columns for Pairplot", df.columns, default=df.columns[:3])
if pairplot_columns:
sns.pairplot(df[pairplot_columns], diag_kind='kde', palette='coolwarm', plot_kws={'edgecolor': 'black'})
plt.suptitle('Pairplot of Selected Features', y=1.02, fontsize=16, fontweight='bold')
st.pyplot(plt)

# Regression Plot: Iron vs Nickel with a trendline
if 'iron' in df.columns and 'nickel' in df.columns:
st.write("### ๐Ÿ“ˆ Regression Plot: Iron vs Nickel")
plt.figure(figsize=(10, 6))
sns.regplot(x='iron', y='nickel', data=df, scatter_kws={'s': 50, 'color': 'green'}, line_kws={'color': 'red'})
plt.title('Regression Plot: Iron vs Nickel', fontsize=16, fontweight='bold')
plt.xlabel('Iron Content', fontsize=14)
plt.ylabel('Nickel Content', fontsize=14)
plt.grid(True)
st.pyplot(plt)

# Additional Visualizations
st.write("### ๐Ÿ“Š More Visualizations")



# KDE Plot
if len(selected_columns) >= 1:
st.write(f"### ๐Ÿ“ˆ KDE Plot of {selected_columns[0]}")
plt.figure(figsize=(10, 6))
sns.kdeplot(df[selected_columns[0]], shade=True, color='blue')
plt.title(f'KDE Plot of {selected_columns[0]}', fontsize=16, fontweight='bold')
plt.xlabel(f'{selected_columns[0]}', fontsize=14)
plt.grid(True)
st.pyplot(plt)

# Strip Plot
if len(selected_columns) >= 1:
st.write(f"### ๐ŸŽ‹ Strip Plot of {selected_columns[0]} by Celestial Body")
plt.figure(figsize=(10, 6))
sns.stripplot(x='Celestial Body', y=selected_columns[0], data=df, jitter=True, palette='viridis', size=7)
plt.title(f'Strip Plot of {selected_columns[0]} by Celestial Body', fontsize=16, fontweight='bold')
# Plot 7: Boxplot with column selection
st.write("### ๐Ÿ“ฆ Boxplot")
box_col = st.selectbox("Choose a Column for Boxplot", df.columns, index=0)
if box_col:
st.write(f"### {box_col} by Celestial Body ๐Ÿ“ฆ")
plt.figure(figsize=(12, 6))
sns.boxplot(x='Celestial Body', y=box_col, data=df, palette='rocket')
plt.xticks(rotation=45, fontsize=12)
plt.title(f'{box_col} by Celestial Body', fontsize=16, fontweight='bold')
plt.grid(True)
st.pyplot(plt)

# Hexbin Plot for continuous variables
if len(selected_columns) >= 2:
st.write(f"### ๐Ÿงฎ Hexbin Plot of {selected_columns[0]} vs {selected_columns[1]}")
# Plot 8: Hexbin Plot with column selection
st.write("### ๐Ÿงฎ Hexbin Plot")
hexbin_x = st.selectbox("Choose X-axis for Hexbin Plot", df.columns, index=0)
hexbin_y = st.selectbox("Choose Y-axis for Hexbin Plot", df.columns, index=1)
if hexbin_x and hexbin_y:
st.write(f"### {hexbin_x} vs. {hexbin_y} (Hexbin Plot) ๐ŸŽฒ")
plt.figure(figsize=(10, 6))
plt.hexbin(df[selected_columns[0]], df[selected_columns[1]], gridsize=30, cmap='Purples', edgecolors='black')
plt.hexbin(df[hexbin_x], df[hexbin_y], gridsize=30, cmap='Purples', edgecolors='black')
plt.colorbar(label='Count')
plt.title(f'Hexbin Plot of {selected_columns[0]} vs {selected_columns[1]}', fontsize=16, fontweight='bold')
plt.title(f'Hexbin Plot of {hexbin_x} vs {hexbin_y}', fontsize=16, fontweight='bold')
plt.grid(True)
st.pyplot(plt)

Expand Down

0 comments on commit 2baa4e3

Please sign in to comment.