Jan*_*Jan 4 python interactive matplotlib event-handling picker
此示例使单击图例从而更改图成为可能。
我想做类似的事情,但不要单击图例,而只需单击图中的线即可。我试图这样做:
self.ax = self.fig.add_subplot(1,2,1)
data = NP.array(2,10) #filled with numbers
self.x = NP.arange(2)
for line in range(len(data[0,:])):
self.ax.plot(self.x, data[:,line], picker=5)
Run Code Online (Sandbox Code Playgroud)
在每个循环中,都会绘制一条额外的线。一条线包含2个点,所以它画一条直线。但是现在,每个循环的选择器都是相同的,因此无论我单击哪一行,我编写用来操纵单击的行的命令始终会影响第一行。有办法改善吗?
您要这样吗?单击一行时,它将被隐藏,而再次单击“空”位置时,将显示它。
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
fig, ax = plt.subplots()
for i in range(1, 10):
ax.plot(x, i * x + x, picker=5)
def on_pick(event):
event.artist.set_visible(not event.artist.get_visible())
fig.canvas.draw()
fig.canvas.callbacks.connect('pick_event', on_pick)
plt.show()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2519 次 |
| 最近记录: |