import matplotlib.pyplot as plt
import numpy as np
np.random.seed(42)
# Create a straight line (45-degree angle)
x_line = np.linspace(0, 10, 100)
y_line = x_line
# Add some random points around the line
num_points = 20
x_points = np.linspace(2, 8, num_points) # Adjust the range as needed
y_points = x_points + np.random.normal(0, 0.5, num_points) # Add some randomness
# Plot the line
plt.plot(x_line, y_line, label='Line', color='blue')
# Plot the points
plt.scatter(x_points, y_points, label='Points', color='red')
# Set labels and title
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Scatter Plot Around a Line')
# Show legend
plt.legend()
# Display the plot
plt.show()
Click Run or press shift + ENTER to run code