Search⌘ K
AI Features

Plotting Sin and Cos Waves

Explore how to use NumPy and Matplotlib to create plots of sine and cosine waves. Understand how to generate data points with NumPy's linspace and visualize functions using Matplotlib's pyplot. This lesson helps you develop practical skills for graphing mathematical functions efficiently in Python.

Introduction to Matplotlib

Matplotlib is a visualization library in Python for plotting 2D array plots. It is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. It can be used to plot all sorts of graphs like line, bar, scatter, histogram, and so on.

We’ll import Matplotlib into our code like so:

from matplotlib import pyplot as plt
or
import matplotlib.pyplot as plt

The new thing here is: import matplotlib.pyplot as plt. We are importing it as ...