import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-100, 100, 1000)
y1 = x
y2 = x ** 2
y3 = x ** +2 * x
fig = plt.figure()
subplot1 = fig.add_subplot(3, 1, 1)
subplot2 = fig.add_subplot(3, 1, 2)
subplot3 = fig.add_subplot(3, 1, 3)
subplot1.plot(x, y1, '-r')
subplot2.plot(x, y2, '-b')
subplot3.plot(x, y3, '-.g')
plt.ylim(-1000, 1000)
plt.legend()
plt.show()
绘制子图
fig = plt.figure()
subplot1 = fig.add_subplot(3, 1, 1)
subplot2 = fig.add_subplot(3, 1, 2)
subplot3 = fig.add_subplot(3, 1, 3)
subplot1.plot(x, y1, '-r')
subplot2.plot(x, y2, '-b')
subplot3.plot(x, y3, '-.g')