Practical Exercises - Chapter 7
Exercise 1: Basic Line Plot
Create a simple line plot using Matplotlib to visualize the function \( y = x^2 \) for \( x \) ranging from 0 to 10.
Solution:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y = x ** 2
plt.plot(x, y)
plt.xlabel('x')
plt.ylabel('y')
plt.title('y = x^2')
plt.show()
Exercise 2: Bar Chart with Seaborn
Create a bar chart using Seaborn to visualize the average petal length for each species in the Iris dataset.
Solution:
import seaborn as sns
df = sns.load_dataset('iris')
sns.barplot(x='species', y='petal_length', data=df)
plt.show()
Exercise 3: Scatter Plot Matrix
Use Seaborn to create a scatter plot matrix of the Iris dataset focusing on the variables 'sepal_length', 'sepal_width', 'petal_length', and 'petal_width'.
Solution:
sns.pairplot(df, vars=['sepal_length', &apos...