0
0
Data Analysis Pythondata~5 mins

Scatter plots in Data Analysis Python

Choose your learning style9 modes available
Introduction

Scatter plots help us see how two things relate to each other by showing points on a graph.

To check if there is a pattern between hours studied and exam scores.
To see if taller people tend to weigh more.
To explore the relationship between temperature and ice cream sales.
To find out if advertising budget affects product sales.
To spot groups or clusters in data points.
Syntax
Data Analysis Python
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.

Examples
Basic scatter plot with default blue circles.
Data Analysis Python
plt.scatter([1, 2, 3], [4, 5, 6])
plt.show()
Scatter plot with red 'x' markers.
Data Analysis Python
plt.scatter([10, 20, 30], [15, 25, 35], color='red', marker='x')
plt.show()
Scatter plot using columns from a data table with labels and title.
Data Analysis Python
plt.scatter(data['age'], data['income'])
plt.xlabel('Age')
plt.ylabel('Income')
plt.title('Age vs Income')
plt.show()
Sample Program

This program shows how exam scores increase as hours studied increase using a scatter plot.

Data Analysis Python
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()
OutputSuccess
Important Notes

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.

Summary

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.