Max*_*Noe 12
如果要使用相同x 轴的两个子图,则可以在创建第二个轴时使用sharex
-keyword:
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax1 = fig.add_subplot(2, 1, 1)
ax2 = fig.add_subplot(2, 1, 2, sharex=ax1)
t = np.linspace(0, 1, 1000)
ax1.plot(t, np.sin(2 * np.pi * t))
ax2.plot(t, np.cos(2 * np.pi * t))
plt.show()
Run Code Online (Sandbox Code Playgroud)