Spaces:
Build error
Build error
| import streamlit as st | |
| import pandas as pd | |
| import plotly.express as px | |
| import matplotlib.pyplot as plt | |
| import seaborn as sns | |
| # Load your dataset here | |
| df = pd.read_csv('your_data.csv') # Replace with your actual dataset file | |
| # Streamlit Interface for Plotting Scatter Plot and Simple Chart | |
| def streamlit_interface(): | |
| st.title("Interactive Data Visualization App") | |
| # Display dataframe | |
| st.write(df.head()) | |
| # Plot interactive scatter plot with Plotly | |
| scatter_fig = px.scatter(df, x='column_x', y='column_y', color='category_column', title="Interactive Scatter Plot") | |
| st.plotly_chart(scatter_fig) | |
| # Input fields for custom plotting | |
| x_values = st.text_input("Enter X values (comma-separated)", "1,2,3,4,5") | |
| y_values = st.text_input("Enter Y values (comma-separated)", "2,4,6,8,10") | |
| # Button to plot custom chart | |
| if st.button("Plot Custom Chart"): | |
| plot_custom_chart(x_values, y_values) | |
| # Correlation Heatmap using Seaborn | |
| st.subheader("Correlation Heatmap") | |
| plot_correlation_heatmap(df) | |
| # Function to plot custom chart | |
| def plot_custom_chart(x_values, y_values): | |
| try: | |
| # Convert the X and Y values from string input to lists of integers | |
| x_vals = list(map(int, x_values.split(','))) | |
| y_vals = list(map(int, y_values.split(','))) | |
| # Ensure both X and Y values have the same length | |
| if len(x_vals) != len(y_vals): | |
| st.error("Error: X and Y values must have the same number of elements.") | |
| return | |
| # Plot using Matplotlib | |
| plt.figure(figsize=(8, 5)) | |
| plt.plot(x_vals, y_vals, marker='o', color='b', label="Data Points") | |
| plt.title("Custom Data Visualization") | |
| plt.xlabel("X Values") | |
| plt.ylabel("Y Values") | |
| plt.grid(True) | |
| plt.legend() | |
| # Display the plot | |
| st.pyplot(plt) | |
| except ValueError: | |
| st.error("Error: Please make sure the values are valid integers.") | |
| # Function to plot correlation heatmap | |
| def plot_correlation_heatmap(df): | |
| corr = df.corr() # Calculate correlation matrix | |
| plt.figure(figsize=(10, 8)) | |
| sns.heatmap(corr, annot=True, cmap='coolwarm', fmt='.2f') | |
| plt.title('Correlation Heatmap') | |
| st.pyplot(plt) # Display in Streamlit | |
| # Run the Streamlit interface | |
| if __name__ == "__main__": | |
| streamlit_interface() | |