Student Activity
Student Activity Guide:
1) Introduction to Matplotlib and Seaborn
Learn the basics of
matplotlibandseabornfor data visualization.Understand how to create basic plots.
Example Code:
import matplotlib.pyplot as plt
import seaborn as sns
# Simple line plot
x = [1, 2, 3, 4, 5]
y = [10, 15, 7, 20, 25]
plt.plot(x, y)
plt.show()Student Exercise: Create a simple plot using matplotlib with different datasets.
2) Creating Line, Bar, and Scatter Plots
Use
matplotlibto create different types of plots.Understand the differences between line, bar, and scatter plots.
Example Code:
# Line Plot
plt.plot(x, y, marker='o', linestyle='-', color='b', label='Line Plot')
plt.xlabel('X Axis')
plt.ylabel('Y Axis')
plt.title('Line Plot Example')
plt.legend()
plt.show()
# Bar Plot
categories = ['A', 'B', 'C', 'D']
values = [10, 20, 15, 25]
plt.bar(categories, values, color='green')
plt.title('Bar Chart Example')
plt.show()
# Scatter Plot
plt.scatter(x, y, color='red', label='Scatter Data')
plt.xlabel('X Axis')
plt.ylabel('Y Axis')
plt.title('Scatter Plot Example')
plt.legend()
plt.show()Student Exercise: Create a bar plot for a dataset with different categories and values. Also, create a scatter plot comparing two sets of values.
3) Customizing Plots with Labels, Legends, and Colors
Learn how to modify charts with labels, legends, and colors.
Customize grid styles and tick marks.
Example Code:
plt.plot(x, y, marker='o', linestyle='--', color='purple', label='Customized Line')
plt.xlabel('X Values', fontsize=12, color='blue')
plt.ylabel('Y Values', fontsize=12, color='red')
plt.title('Customized Plot')
plt.legend()
plt.grid(True)
plt.show()Student Exercise: Customize an existing plot by changing the colors, line styles, and grid appearance.
4) Interactive Visualizations with Seaborn
Use
seabornto enhance visualization aesthetics.Create interactive and stylish plots using
seaborn.
Example Code:
# Sample dataset
import seaborn as sns
import pandas as pd
data = {'Category': ['A', 'B', 'C', 'D', 'E'], 'Values': [10, 20, 15, 30, 25]}
df = pd.DataFrame(data)
# Seaborn bar plot
sns.barplot(x='Category', y='Values', data=df, palette='viridis')
plt.title('Seaborn Bar Chart')
plt.show()
# Seaborn scatter plot
sns.scatterplot(x=x, y=y, hue=y, size=y, palette='coolwarm', sizes=(20, 200))
plt.title('Seaborn Scatter Plot')
plt.show()Student Exercise: Use seaborn to create a heatmap or violin plot using a sample dataset.
Last updated