...

/

Plotting Multiple Curves

Plotting Multiple Curves

In this lesson, we will learn some different ways of plotting multiple graphs and how to label them.

In this course, we will be using the object-oriented approach when working with matplotlib.The main idea with object-oriented programming is to have objects that one can apply functions and actions to, and no object or program states should be global. The real advantage of the object-oriented approach in plotting becomes apparent when more than one figure is created, or when a figure contains more than one plot.

Multiple curves on the same graph #

We can draw multiple curves on the same graph by repeatedly using the plot command.

Press + to interact
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 2 * np.pi , 100)
y1 = np.sin(x)
y2 = np.cos(x)
plt.plot(x, y1) # curve 1
plt.plot(x, y2) # curve 2
plt.plot(x, y1 + y2) # curve 3

If you ...