|
|
import streamlit as st |
|
|
import pandas as pd |
|
|
import matplotlib.pyplot as plt |
|
|
import seaborn as sns |
|
|
|
|
|
|
|
|
def plot_bar_chart(df): |
|
|
plt.figure(figsize=(8, 6)) |
|
|
sns.barplot(x='Category', y='Value', data=df) |
|
|
plt.title('Category vs Value') |
|
|
plt.xlabel('Category') |
|
|
plt.ylabel('Value') |
|
|
plt.tight_layout() |
|
|
return plt |
|
|
|
|
|
|
|
|
def plot_line_chart(df): |
|
|
plt.figure(figsize=(8, 6)) |
|
|
sns.lineplot(x='Category', y='Value', data=df) |
|
|
plt.title('Category vs Value') |
|
|
plt.xlabel('Category') |
|
|
plt.ylabel('Value') |
|
|
plt.tight_layout() |
|
|
return plt |
|
|
|
|
|
|
|
|
def plot_pie_chart(df): |
|
|
plt.figure(figsize=(8, 6)) |
|
|
df.set_index('Category')['Value'].plot.pie(autopct='%1.1f%%', figsize=(8, 6)) |
|
|
plt.title('Category Distribution') |
|
|
return plt |
|
|
|
|
|
|
|
|
st.title('Advanced Data Visualization App') |
|
|
|
|
|
|
|
|
uploaded_file = st.file_uploader("Upload your CSV file", type=["csv"]) |
|
|
|
|
|
if uploaded_file is not None: |
|
|
|
|
|
df = pd.read_csv(uploaded_file) |
|
|
|
|
|
|
|
|
st.write(df) |
|
|
|
|
|
|
|
|
chart_type = st.selectbox('Select the chart type:', ['Bar Chart', 'Line Chart', 'Pie Chart']) |
|
|
|
|
|
|
|
|
if chart_type == 'Bar Chart': |
|
|
st.pyplot(plot_bar_chart(df)) |
|
|
elif chart_type == 'Line Chart': |
|
|
st.pyplot(plot_line_chart(df)) |
|
|
elif chart_type == 'Pie Chart': |
|
|
st.pyplot(plot_pie_chart(df)) |
|
|
|
|
|
|