Data Science — Data Visualization
Matplotlib
import matplotlib.pyplot as plt
# Line plot
plt.plot([1, 2, 3, 4], [1, 4, 2, 3])
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Line Plot')
plt.show()
# Scatter plot
plt.scatter([1, 2, 3, 4], [1, 4, 2, 3])
plt.show()
# Histogram
plt.hist([1, 2, 2, 3, 3, 3, 4, 4, 4, 4])
plt.show()
Seaborn
import seaborn as sns
import pandas as pd
# Load dataset
tips = sns.load_dataset('tips')
# Distribution plot
sns.histplot(data=tips, x='total_bill')
plt.show()
# Box plot
sns.boxplot(data=tips, x='day', y='total_bill')
plt.show()
# Heatmap
sns.heatmap(tips.corr(), annot=True)
plt.show()
Plotly
import plotly.express as px
# Interactive scatter
fig = px.scatter(tips, x='total_bill', y='tip', color='sex')
fig.show()
# Interactive line
fig = px.line(x=[1,2,3], y=[1,4,2])
fig.show()
Best practices
- Choose right chart type
- Label axes clearly
- Use appropriate colors
- Tell a story
Mini Practice
- Create line plots
- Make scatter plots
- Build heatmaps
- Use interactive plots
Up Next
Continue with EDA - Exploratory Data Analysis.
Related Topics
Frequently Asked Questions about Data Visualization
What is Data Visualization in Data Science?
Data Visualization is a fundamental concept in Data Science. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Data Visualization?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Data Visualization.
Why is Data Visualization important in Data Science?
Data Visualization is essential for Data Science development. Understanding this concept will help you write better code and solve real-world problems more effectively.