Spaces:
Sleeping
Sleeping
Create 40_simpleline.py
Browse files- pages/40_simpleline.py +28 -0
pages/40_simpleline.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Initialize sliders
|
| 6 |
+
x = st.slider('X position', min_value=0.0, max_value=10.0, value=5.0, step=0.1)
|
| 7 |
+
w = st.slider('W (slope)', min_value=-10.0, max_value=10.0, value=1.0, step=0.1)
|
| 8 |
+
b = st.slider('B (intercept)', min_value=-10.0, max_value=10.0, value=0.0, step=0.1)
|
| 9 |
+
|
| 10 |
+
# Calculate y based on the equation y = w * x + b
|
| 11 |
+
y = w * x + b
|
| 12 |
+
|
| 13 |
+
# Create the plot
|
| 14 |
+
fig, ax = plt.subplots()
|
| 15 |
+
ax.axhline(y=2, color='gray', linestyle='--') # First horizontal line
|
| 16 |
+
ax.axhline(y=-2, color='gray', linestyle='--') # Second horizontal line
|
| 17 |
+
ax.plot(x, y, 'ro') # Plot the point
|
| 18 |
+
|
| 19 |
+
# Set plot limits and labels
|
| 20 |
+
ax.set_xlim(0, 10)
|
| 21 |
+
ax.set_ylim(-10, 10)
|
| 22 |
+
ax.set_xlabel('X-axis')
|
| 23 |
+
ax.set_ylabel('Y-axis')
|
| 24 |
+
ax.set_title(f'y = {w} * x + {b}')
|
| 25 |
+
ax.grid(True)
|
| 26 |
+
|
| 27 |
+
# Display the plot in Streamlit
|
| 28 |
+
st.pyplot(fig)
|