1  Introduction to Matplotlib

Matplotlib is one of the most well-known libraries for data visualization in Python. It allows the creation of static, animated, and interactive plots with high flexibility.

1.1 Why Matplotlib?

  • Broad Support: Works well with NumPy, Pandas, and SciPy.
  • High Customizability: Full control over plots.
  • Integration with Jupyter Notebooks: Ideal for interactive data analysis.
  • Compatibility: Supports various output formats (PNG, SVG, PDF, etc.).

1.2 Alternatives to Matplotlib

While Matplotlib is powerful, there are alternatives that may be better suited for specific purposes: - Seaborn: Built on top of Matplotlib, simplifies statistical visualizations. - Plotly: Creates interactive plots, great for dashboards. - Bokeh: Ideal for web applications with interactive visualizations.

1.3 First Example: Plotting a Simple Line

import matplotlib.pyplot as plt
import numpy as np

# Example data
t = np.linspace(0, 10, 100)
y = np.sin(t)

# Create the plot
plt.plot(t, y, label='sin(t)')
plt.xlabel('Time (s)')
plt.ylabel('Amplitude')
plt.title('Simple Line Plot')
plt.legend()
plt.show()

This simple example demonstrates how to visualize a sine curve using Matplotlib.

1.4 Next Steps

In the next chapter, we will explore the different types of plots that Matplotlib offers.