gpt4 book ai didi

python - Matplotlib 缩放事件图例选择器未更新

转载 作者:行者123 更新时间:2023-12-01 08:57:28 28 4
gpt4 key购买 nike

我有下面的代码隐藏/显示一行。然而,当我放大时,它似乎不起作用。图例需要以某种方式刷新?

fig, ax = plt.subplots(2,1, sharex=True)

ax[0].grid(True)
ax[0].set_title(date)
lines1 = ax[0].plot(x, y)

ax[1].set_xlabel('time')
ax[1].grid(True)
lines2 = ax[1].plot(x2, y2)

leg1 = fig.legend(lines1, header1, 'upper left')
leg2 = fig.legend(lines2, header2, 'lower left')

lined = dict()
for legline, origline in zip(leg1.get_lines(),lines1):
legline.set_picker(5)
lined[legline] = origline
for legline, origline in zip(leg2.get_lines(),lines2):
legline.set_picker(5)
lined[legline] = origline

def onpick(event):
legline = event.artist
origline = lined[legline]
vis = not origline.get_visible()
origline.set_visible(vis)
if vis:
legline.set_alpha(1.0)
else:
legline.set_alpha(0.2)
fig.canvas.draw()


fig.canvas.mpl_connect('pick_event', onpick)

最佳答案

关于python - Matplotlib 缩放事件图例选择器未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52697206/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com