hussain786110 commited on
Commit
ddec71e
·
verified ·
1 Parent(s): 9433004

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -98
app.py CHANGED
@@ -1,34 +1,51 @@
1
  import streamlit as st
2
- import matplotlib.pyplot as plt
3
- import plotly.express as px
4
  import pandas as pd
 
 
 
5
 
6
- # Load your data (replace with your actual dataset)
7
- df = pd.read_csv('your_data.csv')
8
 
9
- # Create an interactive scatter plot
10
- fig = px.scatter(df, x='column_x', y='column_y', color='category_column', title="Interactive Scatter Plot")
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- # Show the plot
13
- fig.show()
 
14
 
 
 
 
15
 
16
- # Function to plot the chart
17
- def plot_chart(x_values, y_values):
18
  try:
19
  # Convert the X and Y values from string input to lists of integers
20
  x_vals = list(map(int, x_values.split(',')))
21
  y_vals = list(map(int, y_values.split(',')))
22
-
23
  # Ensure both X and Y values have the same length
24
  if len(x_vals) != len(y_vals):
25
  st.error("Error: X and Y values must have the same number of elements.")
26
  return
27
-
28
- # Create a plot
29
  plt.figure(figsize=(8, 5))
30
  plt.plot(x_vals, y_vals, marker='o', color='b', label="Data Points")
31
- plt.title("Data Visualization")
32
  plt.xlabel("X Values")
33
  plt.ylabel("Y Values")
34
  plt.grid(True)
@@ -40,91 +57,16 @@ def plot_chart(x_values, y_values):
40
  except ValueError:
41
  st.error("Error: Please make sure the values are valid integers.")
42
 
43
- # Streamlit interface
44
- def main():
45
- st.title("Data Visualization App")
46
-
47
- # Input fields for X and Y values
48
- x_values = st.text_input("Enter X values (comma-separated)", "1,2,3,4,5")
49
- y_values = st.text_input("Enter Y values (comma-separated)", "2,4,6,8,10")
50
-
51
- # Button to plot the chart
52
- if st.button("Plot Chart"):
53
- plot_chart(x_values, y_values)
54
 
55
- # Run the app
56
  if __name__ == "__main__":
57
- main()
58
- import dash
59
- from dash import dcc, html
60
- import plotly.express as px
61
- import pandas as pd
62
-
63
- # Load data
64
- df = pd.read_csv('your_data.csv')
65
-
66
- # Create Dash app
67
- app = dash.Dash(__name__)
68
-
69
- # Generate a plotly chart
70
- fig = px.scatter(df, x='column_x', y='column_y', color='category_column', title="Interactive Scatter Plot")
71
-
72
- # Define the layout with a dropdown for filtering
73
- app.layout = html.Div([
74
- html.H1("Interactive Data Visualization"),
75
- dcc.Dropdown(
76
- id='category-dropdown',
77
- options=[{'label': i, 'value': i} for i in df['category_column'].unique()],
78
- value=df['category_column'].unique()[0] # Default value
79
- ),
80
- dcc.Graph(id='scatter-plot', figure=fig)
81
- ])
82
-
83
- # Callback to update figure based on dropdown selection
84
- @app.callback(
85
- dash.dependencies.Output('scatter-plot', 'figure'),
86
- [dash.dependencies.Input('category-dropdown', 'value')]
87
- )
88
- def update_graph(selected_category):
89
- filtered_df = df[df['category_column'] == selected_category]
90
- return px.scatter(filtered_df, x='column_x', y='column_y', color='category_column', title="Filtered Scatter Plot")
91
-
92
- # Run the app
93
- if __name__ == '__main__':
94
- app.run_server(debug=True)
95
-
96
-
97
- import streamlit as st
98
- import pandas as pd
99
-
100
- # Load your data (use caching to improve performance)
101
- @st.cache
102
- def load_data():
103
- return pd.read_csv('your_data.csv')
104
-
105
- # Load data
106
- df = load_data()
107
-
108
- # Display the data in Streamlit
109
- st.write(df.head())
110
-
111
- # Display a simple plot
112
- import matplotlib.pyplot as plt
113
- fig, ax = plt.subplots()
114
- ax.scatter(df['column_x'], df['column_y'])
115
- st.pyplot(fig)
116
- import seaborn as sns
117
- import matplotlib.pyplot as plt
118
-
119
- # Generate a correlation matrix
120
- corr = df.corr()
121
-
122
- # Create a heatmap
123
- plt.figure(figsize=(10, 8))
124
- sns.heatmap(corr, annot=True, cmap='coolwarm', fmt='.2f')
125
- plt.title('Correlation Heatmap')
126
-
127
- # Display the heatmap
128
- plt.show()
129
 
130
 
 
1
  import streamlit as st
 
 
2
  import pandas as pd
3
+ import plotly.express as px
4
+ import matplotlib.pyplot as plt
5
+ import seaborn as sns
6
 
7
+ # Load your dataset here
8
+ df = pd.read_csv('your_data.csv') # Replace with your actual dataset file
9
 
10
+ # Streamlit Interface for Plotting Scatter Plot and Simple Chart
11
+ def streamlit_interface():
12
+ st.title("Interactive Data Visualization App")
13
+
14
+ # Display dataframe
15
+ st.write(df.head())
16
+
17
+ # Plot interactive scatter plot with Plotly
18
+ scatter_fig = px.scatter(df, x='column_x', y='column_y', color='category_column', title="Interactive Scatter Plot")
19
+ st.plotly_chart(scatter_fig)
20
+
21
+ # Input fields for custom plotting
22
+ x_values = st.text_input("Enter X values (comma-separated)", "1,2,3,4,5")
23
+ y_values = st.text_input("Enter Y values (comma-separated)", "2,4,6,8,10")
24
 
25
+ # Button to plot custom chart
26
+ if st.button("Plot Custom Chart"):
27
+ plot_custom_chart(x_values, y_values)
28
 
29
+ # Correlation Heatmap using Seaborn
30
+ st.subheader("Correlation Heatmap")
31
+ plot_correlation_heatmap(df)
32
 
33
+ # Function to plot custom chart
34
+ def plot_custom_chart(x_values, y_values):
35
  try:
36
  # Convert the X and Y values from string input to lists of integers
37
  x_vals = list(map(int, x_values.split(',')))
38
  y_vals = list(map(int, y_values.split(',')))
39
+
40
  # Ensure both X and Y values have the same length
41
  if len(x_vals) != len(y_vals):
42
  st.error("Error: X and Y values must have the same number of elements.")
43
  return
44
+
45
+ # Plot using Matplotlib
46
  plt.figure(figsize=(8, 5))
47
  plt.plot(x_vals, y_vals, marker='o', color='b', label="Data Points")
48
+ plt.title("Custom Data Visualization")
49
  plt.xlabel("X Values")
50
  plt.ylabel("Y Values")
51
  plt.grid(True)
 
57
  except ValueError:
58
  st.error("Error: Please make sure the values are valid integers.")
59
 
60
+ # Function to plot correlation heatmap
61
+ def plot_correlation_heatmap(df):
62
+ corr = df.corr() # Calculate correlation matrix
63
+ plt.figure(figsize=(10, 8))
64
+ sns.heatmap(corr, annot=True, cmap='coolwarm', fmt='.2f')
65
+ plt.title('Correlation Heatmap')
66
+ st.pyplot(plt) # Display in Streamlit
 
 
 
 
67
 
68
+ # Run the Streamlit interface
69
  if __name__ == "__main__":
70
+ streamlit_interface()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
 
72