选择事件演示2

计算100个数据集的平均值和标准差(stddev),并绘制平均值vs stddev。单击其中一个mu,sigma点时,绘制生成均值和stddev的数据集中的原始数据。

选择事件演示2

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. X = np.random.rand(100, 1000)
  4. xs = np.mean(X, axis=1)
  5. ys = np.std(X, axis=1)
  6. fig, ax = plt.subplots()
  7. ax.set_title('click on point to plot time series')
  8. line, = ax.plot(xs, ys, 'o', picker=5) # 5 points tolerance
  9. def onpick(event):
  10. if event.artist != line:
  11. return True
  12. N = len(event.ind)
  13. if not N:
  14. return True
  15. figi, axs = plt.subplots(N, squeeze=False)
  16. for ax, dataind in zip(axs.flat, event.ind):
  17. ax.plot(X[dataind])
  18. ax.text(.05, .9, 'mu=%1.3f\nsigma=%1.3f' % (xs[dataind], ys[dataind]),
  19. transform=ax.transAxes, va='top')
  20. ax.set_ylim(-0.5, 1.5)
  21. figi.show()
  22. return True
  23. fig.canvas.mpl_connect('pick_event', onpick)
  24. plt.show()

下载这个示例