Skip to main content

15.8) Multiple Plots


If you want to see multiple figures at once, you have to open new figures. You do this with the figure() function. For example:

plt.figure(1)
plt.plot([5, 6, 7, 8], [1, 1.8, -0.4, 4.3], marker='o')
plt.show()
plt.figure(2)
plt.plot([0.1, 0.2, 0.3, 0.4], [8, -2, 5.3, 4.2],
         linestyle='-.')
plt.show()

If you want to change figure 1 after having created figure 2. You’ll have to call figure 1 again, change the title of the figure and show the plot:

plt.figure(1)   # add a title to figure 1
plt.title('First Plot')
plt.show()

Later you can learn how to combine subplots in the same figure.

Type in the above in a program and run it. Add a third figure.