备注
Go to the end 下载完整示例代码.
共享轴的限制和视图#
通常需要创建两个或多个共享轴的图,例如,两个子图共享一个时间轴.当你在其中一个图上进行平移和缩放时,你希望另一个图也随之移动.为了方便这一点,matplotlib 的 Axes 支持 sharex 和 sharey 属性.当你创建一个 subplot 或 axes 时,你可以传入一个关键字参数,指示你想要与哪个 Axes 共享.
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0, 10, 0.01)
ax1 = plt.subplot(211)
ax1.plot(t, np.sin(2*np.pi*t))
ax2 = plt.subplot(212, sharex=ax1)
ax2.plot(t, np.sin(4*np.pi*t))
plt.show()

标签:component: axis plot-type: line level: beginner