Matplotlib is a versatile 2D plotting library for Python.
It provides a wide range of plot types and customization options.
2. Basic Plotting:
Create line plots, scatter plots, bar plots, and more using matplotlib.pyplot.
3. Customization:
Customize plots with labels, titles, axes, and legends.
Control colors, markers, and line styles.
4. Subplots and Layouts:
Create multiple plots within the same figure using plt.subplot().
Adjust layout using plt.subplots().
5. Save and Export:
Save plots as image files using plt.savefig().
Seaborn:
1. What is Seaborn?
Seaborn is a statistical data visualization library based on Matplotlib.
It simplifies creating informative and attractive visualizations.
2. Built-in Themes and Color Palettes:
Seaborn offers attractive themes and color palettes by default.
Set themes using seaborn.set_style().
3. Statistical Plots:
Create specialized plots like box plots, violin plots, and pair plots.
Use functions like seaborn.boxplot() and seaborn.violinplot().
4. Categorical Plots:
Create bar plots, count plots, and more for categorical data.
Use functions like seaborn.barplot() and seaborn.countplot().
5. Regression and Distribution Plots:
Visualize linear regression with seaborn.regplot()andseaborn.lmplot().
Plot distributions using seaborn.distplot() and seaborn.kdeplot().
Example:
Here's a basic example illustrating the use of Matplotlib and Seaborn:
import numpy as np import matplotlib.pyplot as plt import seaborn as sns
# Generate sample data x = np.linspace(0, 10, 100) y = np.sin(x)
# Matplotlib example: line plot plt.plot(x, y, label="sin(x)") plt.xlabel("X-axis") plt.ylabel("Y-axis") plt.title("Matplotlib Line Plot") plt.legend() plt.show()
In this example, we use Matplotlib to create a line plot and Seaborn to create a scatter plot with color-coded data points.
Both Matplotlib and Seaborn offer extensive documentation and a variety of visualization options to suit different types of data and insights. These libraries are essential tools for effectively conveying information through visual representations.