Introduction
Scatter plots help us see how two things relate to each other by showing points on a graph.
Scatter plots help us see how two things relate to each other by showing points on a graph.
plt.scatter(x, y, color='blue', marker='o') plt.xlabel('X-axis label') plt.ylabel('Y-axis label') plt.title('Title of the plot') plt.show()
x and y are lists or arrays of numbers.
You can change the color and shape of points with color and marker.
plt.scatter([1, 2, 3], [4, 5, 6]) plt.show()
plt.scatter([10, 20, 30], [15, 25, 35], color='red', marker='x') plt.show()
plt.scatter(data['age'], data['income']) plt.xlabel('Age') plt.ylabel('Income') plt.title('Age vs Income') plt.show()
This program shows how exam scores increase as hours studied increase using a scatter plot.
import matplotlib.pyplot as plt # Sample data: hours studied and exam scores hours = [1, 2, 3, 4, 5, 6, 7, 8] scores = [50, 55, 65, 70, 75, 80, 85, 90] plt.scatter(hours, scores, color='green', marker='o') plt.xlabel('Hours Studied') plt.ylabel('Exam Score') plt.title('Scatter Plot of Hours Studied vs Exam Score') plt.grid(True) plt.show()
Scatter plots do not connect points; they just show their position.
Adding labels and a title helps others understand your plot.
Use grid lines to make reading values easier.
Scatter plots show relationships between two sets of numbers.
They help find patterns, trends, or groups in data.
Labels and colors make scatter plots clearer and more informative.
plt.scatter(x, y) to create scatter plots.plt.plot(x, y, kind='scatter') is incorrect syntax; plt.plot does not take kind='scatter'. plt.bar(x, y) creates bar charts. plt.scatterplot(x, y) is not a valid matplotlib function.import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [10, 20, 25, 30]
plt.scatter(x, y)
plt.title('Test Plot')
plt.xlabel('X axis')
plt.ylabel('Y axis')
plt.show()plt.scatter(x, y) which plots points at given x and y coordinates. Titles and labels are added correctly.import matplotlib.pyplot as plt x = [1, 2, 3] y = [4, 5] plt.scatter(x, y) plt.show()
Pass the test and this pattern moves unknown