import streamlit as st import matplotlib.pyplot as plt # 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(2, 1, figsize=(6, 4), gridspec_kw={'height_ratios': [1, 1]}) fig.subplots_adjust(hspace=0.5) # Plot for the x-axis ax[0].hlines(0, 0, 10, color='blue', linestyle='--') # X-axis ax[0].plot(x, 0, 'ro') # Plot the x point ax[0].set_xlim(0, 10) ax[0].set_ylim(-1, 1) ax[0].set_xlabel('X-axis') ax[0].set_yticks([]) # Hide y-axis ticks ax[0].set_title('X-axis Position') ax[0].grid(True) # Plot for the y-axis ax[1].hlines(0, -10, 10, color='blue', linestyle='--') # Y-axis ax[1].plot(y, 0, 'ro') # Plot the y point ax[1].set_xlim(-10, 10) ax[1].set_ylim(-1, 1) ax[1].set_xlabel('Y-axis') ax[1].set_yticks([]) # Hide y-axis ticks ax[1].set_title(f'y = {w} * x + {b}') ax[1].grid(True) # Display the plot in Streamlit st.pyplot(fig)