Data Visualization

Loading concept...

🎨 Data Visualization: Painting Pictures with Data

Imagine you have a box full of colorful LEGO bricks. Each brick represents a piece of information. Now, instead of just counting them, what if you could arrange them to create beautiful pictures that tell a story? That’s exactly what data visualization does!


🌟 The Magic of Seeing Data

Think about it like this: You have a treasure chest full of numbers. If someone just reads you a list of 100 numbers, you’ll probably fall asleep! But what if those numbers became colorful bars, dots, or lines on a picture? Suddenly, the story jumps out at you!

Data visualization is like turning boring numbers into exciting pictures. And in Python, we have two amazing painting tools:

  • Matplotlib - The grandfather of Python charts. Simple but powerful!
  • Seaborn - The stylish grandchild. Makes everything look beautiful automatically!

πŸ–ŒοΈ Matplotlib: Your First Paintbrush

What is Matplotlib?

Imagine you have a blank canvas and a box of crayons. Matplotlib gives you that canvas and all the tools to draw whatever you want. It’s like the basic LEGO set - you can build anything!

Getting Started

import matplotlib.pyplot as plt

# Your first painting!
plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
plt.show()

That’s it! You just drew your first line! The first list [1, 2, 3, 4] tells Python where to put dots horizontally. The second list [1, 4, 9, 16] tells Python how high each dot should be.


πŸ“Š Line Charts: Connecting the Dots

Line charts are perfect for showing how things change over time. Like tracking how tall you grow each year!

import matplotlib.pyplot as plt

months = ['Jan', 'Feb', 'Mar', 'Apr']
ice_cream_sales = [100, 120, 180, 220]

plt.plot(months, ice_cream_sales)
plt.title('Ice Cream Sales')
plt.xlabel('Month')
plt.ylabel('Sales ($)')
plt.show()

What’s happening?

  • plt.plot() draws the line
  • plt.title() gives your picture a name
  • plt.xlabel() labels the bottom
  • plt.ylabel() labels the side
  • plt.show() displays your masterpiece!

πŸ“Š Bar Charts: Building Blocks

Bar charts are like building towers with blocks. The taller the tower, the bigger the number!

import matplotlib.pyplot as plt

fruits = ['Apples', 'Bananas', 'Oranges']
quantities = [25, 40, 30]

plt.bar(fruits, quantities, color='orange')
plt.title('Fruit Basket')
plt.show()

Pro tip: Use color='orange' to pick your favorite color!


πŸ”΅ Scatter Plots: Sprinkle Dots Everywhere

What if your data points don’t connect in a line? Scatter plots just sprinkle dots wherever the data lives!

import matplotlib.pyplot as plt

height = [150, 160, 165, 170, 175]
weight = [50, 55, 60, 65, 70]

plt.scatter(height, weight, color='blue')
plt.title('Height vs Weight')
plt.xlabel('Height (cm)')
plt.ylabel('Weight (kg)')
plt.show()

Scatter plots help you see if two things are related. Do taller people tend to weigh more? The dots tell the story!


πŸ₯§ Pie Charts: Slicing the Pizza

Pie charts show how a whole thing is divided into parts. Like cutting a pizza!

import matplotlib.pyplot as plt

activities = ['Sleep', 'School', 'Play', 'Eat']
hours = [8, 7, 5, 4]

plt.pie(hours, labels=activities, autopct='%1.0f%%')
plt.title('My Day')
plt.show()

Magic ingredient: autopct='%1.0f%%' shows the percentage on each slice!


πŸ“Š Histograms: Counting Groups

Histograms group your data into buckets. Imagine sorting marbles by size!

import matplotlib.pyplot as plt

test_scores = [65, 70, 75, 80, 85, 90, 72, 78, 82]

plt.hist(test_scores, bins=5, color='green')
plt.title('Test Score Distribution')
plt.xlabel('Score')
plt.ylabel('Students')
plt.show()

bins=5 means β€œdivide the data into 5 groups”


🎨 Customizing Your Art

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]

plt.figure(figsize=(8, 4))
plt.plot(x, y,
         color='red',
         linewidth=2,
         linestyle='--',
         marker='o')
plt.grid(True)
plt.show()

Your toolbox:

  • figsize=(8, 4) - Size of your canvas
  • color='red' - Line color
  • linewidth=2 - How thick the line is
  • linestyle='--' - Dashed line
  • marker='o' - Circles at each point
  • grid=True - Add helper lines

πŸ“ Multiple Plots: The Gallery Wall

Sometimes you want to show multiple pictures side by side!

import matplotlib.pyplot as plt

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4))

ax1.bar(['A', 'B', 'C'], [10, 20, 15])
ax1.set_title('Sales')

ax2.plot([1, 2, 3], [1, 4, 9])
ax2.set_title('Growth')

plt.tight_layout()
plt.show()

plt.subplots(1, 2) creates 1 row with 2 columns of pictures!


🌊 Seaborn: The Style Master

What is Seaborn?

If Matplotlib is basic LEGO, Seaborn is like having a professional LEGO designer help you! It makes everything look beautiful with almost no effort.

import seaborn as sns
import matplotlib.pyplot as plt

# Seaborn makes things pretty automatically!
sns.set_theme()  # Turn on the magic

πŸ“Š Seaborn Line Plot

import seaborn as sns
import matplotlib.pyplot as plt

months = ['Jan', 'Feb', 'Mar', 'Apr']
sales = [100, 150, 200, 250]

sns.lineplot(x=months, y=sales)
plt.title('Monthly Sales')
plt.show()

Notice how it looks more polished than basic Matplotlib!


πŸ“Š Seaborn Bar Plot

import seaborn as sns
import matplotlib.pyplot as plt

fruits = ['Apple', 'Banana', 'Orange']
counts = [30, 45, 25]

sns.barplot(x=fruits, y=counts, palette='pastel')
plt.title('Fruit Count')
plt.show()

palette='pastel' gives you beautiful coordinated colors!


πŸ”₯ Heatmaps: The Temperature Map

Heatmaps use colors to show intensity. Like a weather map showing hot and cold areas!

import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np

# Create sample data
data = np.array([[1, 2, 3],
                 [4, 5, 6],
                 [7, 8, 9]])

sns.heatmap(data, annot=True, cmap='YlOrRd')
plt.title('My Heatmap')
plt.show()
  • annot=True - Show numbers in each cell
  • cmap='YlOrRd' - Yellow to Orange to Red colors

πŸ“¦ Box Plots: The Data Summary Box

Box plots show you a quick summary: the middle value, the spread, and any unusual values!

import seaborn as sns
import matplotlib.pyplot as plt

scores = [85, 90, 78, 92, 88, 76, 95, 89]

sns.boxplot(y=scores)
plt.title('Test Scores Summary')
plt.show()

The box shows where most of your data lives. The line in the middle is the median (the middle value).


🎻 Violin Plots: The Fancy Box Plot

Violin plots are like box plots but show the full shape of your data!

import seaborn as sns
import matplotlib.pyplot as plt

data = [65, 70, 70, 75, 75, 75, 80, 80, 85]

sns.violinplot(y=data, color='lightblue')
plt.title('Score Distribution Shape')
plt.show()

The wider parts show where most of your data is clustered!


πŸ”΅ Seaborn Scatter Plot

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset('tips')

sns.scatterplot(data=tips, x='total_bill',
                y='tip', hue='day')
plt.title('Tips by Bill Amount')
plt.show()

hue='day' colors the dots by which day it was. Magic!


πŸ“Š Count Plot: Counting Categories

import seaborn as sns
import matplotlib.pyplot as plt

pets = ['Dog', 'Cat', 'Dog', 'Bird', 'Dog', 'Cat']

sns.countplot(x=pets, palette='Set2')
plt.title('Pet Count')
plt.show()

Seaborn counts for you! No need to calculate first.


πŸ“ˆ Distribution Plot: The Data Shape

import seaborn as sns
import matplotlib.pyplot as plt

ages = [22, 25, 27, 25, 30, 32, 25, 28, 26]

sns.histplot(ages, kde=True)
plt.title('Age Distribution')
plt.show()

kde=True adds a smooth curve showing the overall shape!


πŸ”— Pair Plot: See Everything at Once

When you have multiple columns, pair plot shows ALL relationships!

import seaborn as sns
import matplotlib.pyplot as plt

iris = sns.load_dataset('iris')
sns.pairplot(iris, hue='species')
plt.show()

This creates a grid showing how every column relates to every other column. Super powerful!


🎨 Seaborn Themes

import seaborn as sns

# Different looks!
sns.set_theme(style='darkgrid')   # Dark background
sns.set_theme(style='whitegrid')  # Light background
sns.set_theme(style='ticks')      # Simple with ticks

πŸ† Quick Comparison

graph LR A[Data Visualization] --> B[Matplotlib] A --> C[Seaborn] B --> D[Full Control] B --> E[Basic Styling] B --> F[More Code Needed] C --> G[Built on Matplotlib] C --> H[Beautiful Defaults] C --> I[Less Code Needed]
Feature Matplotlib Seaborn
Control Maximum Good
Beauty Manual Automatic
Code More Less
Learning Start here Add this

🎯 When to Use What?

Use Matplotlib when:

  • You need total control
  • You’re making custom visualizations
  • You want simple, basic charts

Use Seaborn when:

  • You want beautiful charts fast
  • You’re doing statistical analysis
  • You have categorical data

πŸš€ Your Visualization Journey

graph TD A[Start] --> B[Learn Matplotlib Basics] B --> C[Try All Chart Types] C --> D[Add Seaborn for Beauty] D --> E[Combine Both Powers] E --> F[Create Amazing Visuals!]

πŸ’‘ Remember These Magic Words

  • plt.plot() - Draw a line
  • plt.bar() - Draw bars
  • plt.scatter() - Sprinkle dots
  • plt.show() - Display your art!
  • sns.set_theme() - Make it pretty
  • sns.heatmap() - Color by value
  • sns.boxplot() - Show data summary

🌈 The Big Picture

Data visualization is your superpower! Instead of staring at boring numbers, you can now:

  1. See patterns that hide in the data
  2. Tell stories that everyone understands
  3. Make decisions based on what you see
  4. Impress everyone with beautiful charts!

Remember: Matplotlib gives you the brushes, Seaborn makes you an artist. Together, they help you paint the story your data wants to tell!

Now go forth and visualize! Your data is waiting to become beautiful! 🎨✨

Loading story...

No Story Available

This concept doesn't have a story yet.

Story Preview

Story - Premium Content

Please sign in to view this concept and start learning.

Upgrade to Premium to unlock full access to all content.

Interactive Preview

Interactive - Premium Content

Please sign in to view this concept and start learning.

Upgrade to Premium to unlock full access to all content.

No Interactive Content

This concept doesn't have interactive content yet.

Cheatsheet Preview

Cheatsheet - Premium Content

Please sign in to view this concept and start learning.

Upgrade to Premium to unlock full access to all content.

No Cheatsheet Available

This concept doesn't have a cheatsheet yet.

Quiz Preview

Quiz - Premium Content

Please sign in to view this concept and start learning.

Upgrade to Premium to unlock full access to all content.

No Quiz Available

This concept doesn't have a quiz yet.