Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import numpy as np | |
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| # Streamlit application | |
| def app(): | |
| st.title("Linear Equation Visualizer") | |
| # Input fields for the equation y = mx + c | |
| m = st.number_input("Enter the slope (m):", value=1.0) | |
| c = st.number_input("Enter the y-intercept (c):", value=0.0) | |
| x_value = st.number_input("Enter the x value to predict y:", value=0.0) | |
| # Calculating y based on the input | |
| y = m * x_value + c | |
| # Displaying the calculated y | |
| st.write(f"The calculated y value is: {y}") | |
| # Generating data for the line | |
| x = np.linspace(-10, 10, 100) | |
| y_line = m * x + c | |
| # Plotting the line | |
| plt.figure(figsize=(10, 6)) | |
| plt.plot(x, y_line, '-r', label=f'y = {m}x + {c}') | |
| plt.scatter(x_value, y, color='blue', label='Predicted Point') | |
| plt.title("Graph of y = mx + c") | |
| plt.xlabel("x") | |
| plt.ylabel("y") | |
| plt.legend() | |
| plt.grid(True) | |
| # Displaying the plot | |
| st.pyplot(plt) | |
| if __name__ == "__main__": | |
| app() | |