Spaces:
Sleeping
Sleeping
File size: 1,118 Bytes
1d67140 e6adb31 1d67140 5ae9492 1d67140 5ae9492 ee91411 5ae9492 e73dca0 5ae9492 ee91411 5ae9492 ee91411 5ae9492 1d67140 1b75d5f |
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 29 30 31 32 33 34 35 36 37 38 |
import streamlit as st
import matplotlib.pyplot as plt
# Title
st.title("Interactive Equation Plotter")
# Sidebar sliders
st.sidebar.header("Controls")
x = st.sidebar.slider('X position', min_value=-100.0, max_value=100.0, value=0.0, step=1.0)
w = st.sidebar.slider('W (slope)', min_value=-10.0, max_value=10.0, value=1.0, step=0.1)
b = st.sidebar.slider('B (intercept)', min_value=-100.0, max_value=100.0, value=0.0, step=1.0)
# Calculate y based on the equation y = w * x + b
y = w * x + b
# Create the plot
fig, ax = plt.subplots(figsize=(6, 4))
fig.subplots_adjust(top=0.8, bottom=0.1)
# Plot for the y-axis (top line)
ax.hlines(1, -100, 100, color='blue', linestyle='--') # Y-axis
ax.plot(y, 1, 'ro') # Plot the y point
# Plot for the x-axis (bottom line)
ax.hlines(-1, -100, 100, color='blue', linestyle='--') # X-axis
ax.plot(x, -1, 'ro') # Plot the x point
# Set plot limits and labels
ax.set_xlim(-100, 100)
ax.set_ylim(-2, 2)
ax.set_xlabel('X-axis and Y-axis')
ax.set_yticks([]) # Hide y-axis ticks
ax.set_title(f'y = {w} * x + {b}')
ax.grid(True)
# Display the plot in Streamlit
st.pyplot(fig)
|