注解
Click here 下载完整的示例代码
选择事件演示2¶
计算100个数据集的平均值(mu)和标准差(sigma),并绘制mu与sigma的关系图。当您单击其中一个(mu,sigma)点时,从生成该点的数据集绘制原始数据。

import numpy as np
import matplotlib.pyplot as plt
# Fixing random state for reproducibility
np.random.seed(19680801)
X = np.random.rand(100, 1000)
xs = np.mean(X, axis=1)
ys = np.std(X, axis=1)
fig, ax = plt.subplots()
ax.set_title('click on point to plot time series')
line, = ax.plot(xs, ys, 'o', picker=True, pickradius=5)
def onpick(event):
if event.artist != line:
return True
N = len(event.ind)
if not N:
return True
figi, axs = plt.subplots(N, squeeze=False)
for ax, dataind in zip(axs.flat, event.ind):
ax.plot(X[dataind])
ax.text(.05, .9, 'mu=%1.3f\nsigma=%1.3f' % (xs[dataind], ys[dataind]),
transform=ax.transAxes, va='top')
ax.set_ylim(-0.5, 1.5)
figi.show()
return True
fig.canvas.mpl_connect('pick_event', onpick)
plt.show()
关键词:matplotlib代码示例,codex,python plot,pyplot Gallery generated by Sphinx-Gallery