hussain786110 commited on
Commit
198720a
·
verified ·
1 Parent(s): 3cf5a1c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import matplotlib.pyplot as plt
3
+
4
+ # Function to plot the chart
5
+ def plot_chart(x_values, y_values):
6
+ try:
7
+ # Convert the X and Y values from string input to lists of integers
8
+ x_vals = list(map(int, x_values.split(',')))
9
+ y_vals = list(map(int, y_values.split(',')))
10
+
11
+ # Ensure both X and Y values have the same length
12
+ if len(x_vals) != len(y_vals):
13
+ st.error("Error: X and Y values must have the same number of elements.")
14
+ return
15
+
16
+ # Create a plot
17
+ plt.figure(figsize=(8, 5))
18
+ plt.plot(x_vals, y_vals, marker='o', color='b', label="Data Points")
19
+ plt.title("Data Visualization")
20
+ plt.xlabel("X Values")
21
+ plt.ylabel("Y Values")
22
+ plt.grid(True)
23
+ plt.legend()
24
+
25
+ # Display the plot
26
+ st.pyplot(plt)
27
+
28
+ except ValueError:
29
+ st.error("Error: Please make sure the values are valid integers.")
30
+
31
+ # Streamlit interface
32
+ def main():
33
+ st.title("Data Visualization App")
34
+
35
+ # Input fields for X and Y values
36
+ x_values = st.text_input("Enter X values (comma-separated)", "1,2,3,4,5")
37
+ y_values = st.text_input("Enter Y values (comma-separated)", "2,4,6,8,10")
38
+
39
+ # Button to plot the chart
40
+ if st.button("Plot Chart"):
41
+ plot_chart(x_values, y_values)
42
+
43
+ # Run the app
44
+ if __name__ == "__main__":
45
+ main()
46
+
47
+