๐ Scatter Plot: Numbers vs Their Squares
Understanding relationships between variables is a core part of data analysis. In this guide, we explore how to visualize the relationship between a number and its square using a scatter plot.
๐ Table of Contents
- Concept Overview
- Mathematical Insight
- CSV Data Structure
- Python Code Example
- CLI Output
- Understanding the Plot
- Key Takeaways
- Related Articles
๐ Concept Overview
We are plotting pairs of values:
- Input number (x-axis)
- Its square (y-axis)
Example:
- 2 → 4
- 3 → 9
- 4 → 16
๐ Why Use Scatter Plots?
Scatter plots are ideal for identifying relationships, trends, and patterns between two variables. In this case, they clearly show a curved growth pattern.
๐ Mathematical Insight
The relationship is defined by:
\[ y = x^2 \]This is a quadratic relationship, meaning growth accelerates as x increases.
๐ Expand Explanation
Unlike linear growth \(y = x\), squaring creates exponential-like curvature. This results in a parabola when plotted.
๐ CSV Data Structure
The dataset is stored like this:
Number,Square 1,1 2,4 3,9 4,16 5,25
๐ป Python Code Example
import csv
import matplotlib.pyplot as plt
numbers = []
squares = []
with open('data.csv', 'r') as file:
reader = csv.reader(file)
next(reader) # skip header
for row in reader:
numbers.append(int(row[0]))
squares.append(int(row[1]))
plt.scatter(numbers, squares)
plt.xlabel("Number")
plt.ylabel("Square")
plt.title("Scatter Plot of Numbers vs Squares")
plt.show()
๐ฅ️ CLI Output Example
$ python plot.py Reading CSV... Extracted 5 data points Generating scatter plot... Displaying graph window
๐ Understanding the Plot
Each point represents a pair \((x, x^2)\).
- Points form a curved shape (parabola)
- Growth becomes steeper as x increases
- Demonstrates non-linear relationship
๐ Expand Visualization Insight
If you connect the points, you would see a smooth U-shaped curve. This is characteristic of quadratic functions.
๐ฏ Key Takeaways
- Scatter plots show relationships between variables
- This dataset follows a quadratic pattern
- CSV makes data easy to store and read
- Python simplifies visualization
๐ Final Thoughts
This simple example demonstrates how powerful visualization can be. Even a basic dataset can reveal meaningful patterns when plotted correctly.
Once you understand this, you can scale it to complex datasets and real-world analytics.
No comments:
Post a Comment