我有两个 CheckButtons 小部件,每个小部件有 3 个元素。我想在选择任一 CheckButtons 时读取两个小部件的状态,然后相应地更新图表。
滑块小部件有一个.val
用于返回滑块状态的功能,但 CheckButtons 小部件似乎有点尴尬(或者我遗漏了一些明显的东西)?
简短的例子:
import matplotlib.pyplot as plt
from matplotlib.widgets import CheckButtons
class Example:
def updateChart(self, event):
colour = self.colours.labels # gets labes as text object, is there an easy way of getting the status?
print colour
# measurement = measurements.something
def __init__(self):
colourax = plt.axes([0.5, 0.4, 0.09, 0.2])
measurementax = plt.axes([0.5, 0.6, 0.09, 0.2])
self.colours = CheckButtons(colourax, ('Red', 'Green', 'Blue'), (False, False, False))
self.measurements = CheckButtons(measurementax, ('1', '2', '3'), (False, False, False))
self.colours.on_clicked(self.updateChart)
self.measurements.on_clicked(self.updateChart)
def run(self):
plt.show()
ex = Example()
ex.run()