修改matplotlib复选按钮

2024-04-25 16:57:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我写了一个代码来显示模拟数据的实时反馈。代码使用pyfirmata定义引脚和拉力读数。我已将funcanimation设置为在端口打开时拉动所有12个通道。目前,matplotlib checkbutton用于显示/隐藏频道的实时提要

我想操纵matplotlib checkbutton,以便只读取被选中的通道,而不只是隐藏

matplotlib小部件模块太复杂了,我无法将其分解到可以修改的级别。我想做的是根据每个索引的可见性在每个索引上写一个真/假状态,然后在funcanimation中放入一个嵌套的if语句,以便只读取可见的行。如果有人能给我一个示例代码让我这么做,我将不胜感激

以下是我的一段代码:

##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

谢谢


Tags: 代码inforgetindexlabelsmatplotlibcheck
1条回答
网友
1楼 · 发布于 2024-04-25 16:57:41

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

相关问题 更多 >

    热门问题