Intermediate Practical

Data Visualization with Python

Creating Effective and Insightful Visualizations

Why Data Visualization?

Understand Data

Quickly identify patterns and outliers

Communicate Insights

Tell compelling data stories

Drive Decisions

Support data-driven choices

Python Visualization Libraries

📊 Matplotlib

Foundation library for creating static, animated, and interactive visualizations

pip install matplotlib

📈 Seaborn

Statistical data visualization built on Matplotlib with beautiful default styles

pip install seaborn

🎨 Plotly

Interactive visualizations with zoom, pan, and hover tooltips

pip install plotly

🐼 Pandas Plotting

Quick plotting directly from DataFrames

df.plot()

Common Visualization Types

📊 Bar Charts

Compare categories

plt.bar(x, y)

📈 Line Charts

Show trends over time

plt.plot(x, y)

⚫ Scatter Plots

Explore relationships

plt.scatter(x, y)

📦 Box Plots

Show distributions

plt.boxplot(data)

🔥 Heatmaps

Visualize correlations

sns.heatmap(data)

🥧 Pie Charts

Show proportions

plt.pie(sizes)

Code Example: Healthcare Data Visualization

# Import libraries
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Load healthcare dataset
df = pd.read_csv('patient_data.csv')
# Create figure with subplots
fig, axes = plt.subplots(2, 2, figsize=(12, 10))
# 1. Age distribution
axes[0, 0].hist(df['age'], bins=20, color='skyblue')
axes[0, 0].set_title('Patient Age Distribution')
# 2. Disease by gender
df.groupby('gender')['disease'].value_counts().unstack().plot(
kind='bar', ax=axes[0, 1])
# 3. Correlation heatmap
sns.heatmap(df.corr(), annot=True, ax=axes[1, 0])
# 4. Blood pressure vs age
axes[1, 1].scatter(df['age'], df['blood_pressure'])
plt.tight_layout()
plt.show()

Best Practices

Choose the right chart type for your data and message

Use clear labels and titles to guide interpretation

Keep it simple - avoid chart junk and unnecessary decorations

Use color purposefully - ensure accessibility and meaning

Consider your audience - technical vs. general public

Hands-On Lab

Objective: Create a comprehensive visualization dashboard for healthcare data

Tasks:

  1. 1. Load and explore the provided dataset
  2. 2. Create at least 5 different types of visualizations
  3. 3. Build an interactive dashboard using Plotly
  4. 4. Write interpretations for each visualization

Use Cursor AI to help debug code and generate visualization templates