About Matplotlib
About Matplotlib
Matplotlib is one of the most popular and widely used data visualization libraries in Python.
It provides tools for creating static, animated, and interactive plots in Python. Matplotlib is
especially known for its ability to produce publication-quality figures in a variety of formats
and interactive environments across platforms.
🧩 Key Features
2D Plotting: Line plots, bar charts, histograms, scatter plots, pie charts, etc.
Highly customizable: Colors, labels, axes, legends, and figure size can be customized
extensively.
Multiple output formats: Supports output to PNG, PDF, SVG, EPS, and interactive GUI
backends.
Integration: Works well with NumPy, pandas, and integrates easily with Jupyter
Notebooks.
🔧 Installation
bash
CopyEdit
📊 Basic Example
python
CopyEdit
# Data
x = [1, 2, 3, 4, 5]
y = [2, 4, 1, 8, 7]
# Create plot
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
# Show legend
plt.legend()
plt.show()
Histogram plt.hist()
python
CopyEdit
plt.subplot(1, 2, 1) # 1 row, 2 columns, 1st plot
plt.title("First Plot")
plt.title("Second Plot")
plt.tight_layout()
plt.show()
🛠 Advanced Features
Object-Oriented API: For more control, you can use the Figure and Axes objects.
Example:
python
CopyEdit
plt.style.use('ggplot')