修改matplotlib选中按钮

时间:2020-01-01 19:04:48

标签: python matplotlib

我写了一个代码来显示实时的模拟数据提要。该代码使用pyfirmata定义大头针并读取读数。我将funcanimation设置为在端口打开时拉所有12个通道。当前,matplotlib复选按钮用于显示/隐藏频道的实时供稿。

我想操纵matplotlib选中按钮,以便实际上只读取选中的通道,而不仅仅是隐藏它们。

matplotlib小部件模块对我来说太复杂了,无法分解到可以修改它的水平。我想做的是根据索引的可见性在每个索引上写一个true / false状态,然后在funcanimation中放置一个嵌套的if语句,以仅 read 可见行。如果有人可以与我分享示例代码以允许我这样做,我将不胜感激。

这是我的代码的一部分:

##check buttons
lines = [ln0, ln1, ln2, ln3, ln4, ln5, ln6, ln7, ln8, ln9, ln10, ln11]
labels = [str(ln0.get_label()) for ln0 in lines]
visibility = [ln0.get_visible() for ln0 in lines]
check = CheckButtons(ax1, labels, visibility)
for i, c in enumerate(colour):
    check.labels[i].set_color(c)

def func(label):
    index = labels.index(label)
    lines[index].set_visible(not lines[index].get_visible())

check.on_clicked(func)

## define pins
a0 = due.get_pin('a:0:i')
a1 = due.get_pin('a:1:i') 
a2 = due.get_pin('a:2:i')
a3 = ...

##funcanimation
def rt(i):
    t.append(datetime.now())
    if due.is_open == True:
            T0.append(round(a0.read()*3.3/0.005, 1))
            T1.append(round(a1.read()*3.3/0.005, 1))
            ...

这是运行时的图形和检查按钮: click here

谢谢

1 个答案:

答案 0 :(得分:0)

我知道了。 matplotlib小部件中嵌入了一个get_status函数,该函数返回true和false的元组以指示检查按钮的状态。我用它在funcanimation中编写了一个嵌套的if语句,以便只读取选中的语句。