Gen AI Developer Week 1 — Day 5
Effective data visualization connects raw numbers with actionable insights. Libraries such as Matplotlib and Seaborn enable developers to produce clear, engaging, and insightful visualisations. While Matplotlib offers unparalleled versatility for constructing unique plots, Seaborn makes it easier to create visually appealing and statistically robust visualizations. As part of my Generative AI Developer Week adventure, this essay discusses how these libraries work together to transform data into interesting tales.
Let’s first install matplotlib and seaborn using the below pip command installation.
# Run the below command to install matplotlib and seaborn
pip install matplotlib
pip install seaborn
Now lets import matplotlib and seaborn to get started for this day!
import matplotlib.pyplot as plt
import seaborn as sns
For Matplotlib basics you can refer this article here.
Seaborn Basics — Distribution Plot
# Distribution Plot
# Understand the distribution of a single variable.
import seaborn as sns
import numpy as np
data = np.random.randn(1000) # Random data
sns.histplot(data, kde=True, color='purple')
plt.title('Distribution Plot Example')
plt.show()
Seaborn Basics — Heatmap
# Heatmap
# Visualize correlations or matrix-like data.
data = np.random.rand(5, 5) # Random matrix
sns.heatmap(data, annot=True, cmap='coolwarm')
plt.title('Heatmap Example')
plt.show()
Seaborn Basics — Pairplot
# Pairplot
# Explore relationships between multiple variables in a dataset.
iris = sns.load_dataset('iris') # Loading iris dataset
sns.pairplot(iris, hue='species')
# plt.title('Pairplot Example')
plt.show()
Task — Heatmap
# Task 3: Heatmap
# Use the Iris dataset and create a heatmap showing correlations between features.
import matplotlib.pyplot as plt
import seaborn as sns
iris = sns.load_dataset('iris') # Load Dataset
iris_numeric = iris.select_dtypes(include=['float64', 'int64']) # exclude non numeric data
correlation_matrix = iris_numeric.corr() # create correlational matrix
print(correlation_matrix)
sns.heatmap(correlation_matrix, annot=True, cmap='coolwarm', fmt='.2f', linewidths=0.5) # create heatmap with correlational matrix
plt.title('Heatmap of Iris Dataset Correlations')
plt.show()
plt.savefig('irisHeatMap.png')
Happy Learning!😊.. For any questions or support, feel free to message me on LinkedIn.