bhajay commited on
Commit
acd6674
·
verified ·
1 Parent(s): f3ecb29

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +54 -39
src/streamlit_app.py CHANGED
@@ -1,40 +1,55 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
5
-
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import numpy as np
3
+ import matplotlib.pyplot as plt
4
+
5
+ # Sidebar inputs
6
+ st.sidebar.header("Function Parameters")
7
+ a_0 = st.sidebar.slider("Amplitude of Sine (a₀)", -5.0, 5.0, 1.0, 0.1)
8
+ omega = st.sidebar.slider("Frequency of Sine (ω)", 0.1, 10.0, 1.0, 0.1)
9
+ b_0 = st.sidebar.slider("Initial value of Exp (b₀)", -5.0, 5.0, 1.0, 0.1)
10
+ alpha = st.sidebar.slider("Exponent Coefficient (α)", -5.0, 5.0, 0.5, 0.1)
11
+
12
+ # Main title
13
+ st.title("Damped/undamped vibration characteristic visualiser")
14
+
15
+ # Time vector
16
+ t = np.linspace(0, 10, 1000)
17
+
18
+ # Functions
19
+ y_sin = a_0 * np.sin(omega * t)
20
+ y_exp = b_0 * np.exp(alpha * t)
21
+ y_combined = y_sin * y_exp
22
+
23
+ # Plotting setup
24
+ fig1, ax1 = plt.subplots()
25
+ ax1.plot(t, y_sin, label=r'$a_0 \sin(\omega t)$', color='tab:blue')
26
+ ax1.set_title("Sine Function", fontsize=14)
27
+ ax1.set_xlabel("Time (t)", fontsize=12)
28
+ ax1.set_ylabel("Amplitude", fontsize=12)
29
+ ax1.grid(True)
30
+ ax1.legend()
31
+
32
+ fig2, ax2 = plt.subplots()
33
+ ax2.plot(t, y_exp, label=r'$b_0 e^{\alpha t}$', color='tab:green')
34
+ ax2.set_title("Exponential Function", fontsize=14)
35
+ ax2.set_xlabel("Time (t)", fontsize=12)
36
+ ax2.set_ylabel("Amplitude", fontsize=12)
37
+ ax2.grid(True)
38
+ ax2.legend()
39
+
40
+ fig3, ax3 = plt.subplots()
41
+ ax3.plot(t, y_combined, label=r'$a_0 \sin(\omega t) \cdot b_0 e^{\alpha t}$', color='tab:red')
42
+ ax3.set_title("Combined Function: Sine × Exponential", fontsize=14)
43
+ ax3.set_xlabel("Time (t)", fontsize=12)
44
+ ax3.set_ylabel("Amplitude", fontsize=12)
45
+ ax3.grid(True)
46
+ ax3.legend()
47
+
48
+ # Display plots in layout
49
+ col1, col2 = st.columns(2)
50
+ with col1:
51
+ st.pyplot(fig1)
52
+ with col2:
53
+ st.pyplot(fig2)
54
+
55
+ st.pyplot(fig3)