File size: 847 Bytes
1d67140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import streamlit as st
import matplotlib.pyplot as plt
import numpy as np

# Initialize sliders
x = st.slider('X position', min_value=0.0, max_value=10.0, value=5.0, step=0.1)
w = st.slider('W (slope)', min_value=-10.0, max_value=10.0, value=1.0, step=0.1)
b = st.slider('B (intercept)', min_value=-10.0, max_value=10.0, value=0.0, step=0.1)

# Calculate y based on the equation y = w * x + b
y = w * x + b

# Create the plot
fig, ax = plt.subplots()
ax.axhline(y=2, color='gray', linestyle='--')  # First horizontal line
ax.axhline(y=-2, color='gray', linestyle='--')  # Second horizontal line
ax.plot(x, y, 'ro')  # Plot the point

# Set plot limits and labels
ax.set_xlim(0, 10)
ax.set_ylim(-10, 10)
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.set_title(f'y = {w} * x + {b}')
ax.grid(True)

# Display the plot in Streamlit
st.pyplot(fig)