Spaces:
Running
Running
| import streamlit as st | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| # Streamlit app title | |
| st.title('Interactive Scatter Plot with Noise and Number of Data Points') | |
| # Sidebar sliders for noise and number of data points | |
| noise_level = st.sidebar.slider('Noise Level', 0.0, 2.0, 0.5, step=0.01) | |
| num_points = st.sidebar.slider('Number of Data Points', 10, 100, 50, step=5) | |
| # Generate data | |
| np.random.seed(0) | |
| x = np.linspace(0, 10, num_points) | |
| y = 2 * x + 1 + noise_level * np.random.randn(num_points) | |
| # Create scatter plot | |
| fig, ax = plt.subplots() | |
| ax.scatter(x, y, alpha=0.6) | |
| ax.set_title('Scatter Plot with Noise and Number of Data Points') | |
| ax.set_xlabel('X-axis') | |
| ax.set_ylabel('Y-axis') | |
| # Display plot in Streamlit | |
| st.pyplot(fig) | |