多光标

同时在多个图上显示光标。

此示例生成两个子图,并将光标悬停在一个子图中的数据上,该数据点的值分别显示在两个子图中。

多光标示例

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from matplotlib.widgets import MultiCursor
  4. t = np.arange(0.0, 2.0, 0.01)
  5. s1 = np.sin(2*np.pi*t)
  6. s2 = np.sin(4*np.pi*t)
  7. fig, (ax1, ax2) = plt.subplots(2, sharex=True)
  8. ax1.plot(t, s1)
  9. ax2.plot(t, s2)
  10. multi = MultiCursor(fig.canvas, (ax1, ax2), color='r', lw=1)
  11. plt.show()

下载这个示例