I have two CheckButtons widgets with 3 elements each. I'd like to read the status of both widgets when either one of the CheckButtons is selected then update the chart accordingly.
The slider widget has a .val
for returning the status of a slider, but the CheckButtons widget seems a bit more awkward (or am I missing something obvious)?
short example:
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()
I know it's a bit awkward, but you can check for visibility of on of the cross lines in check boxes.
import matplotlib.pyplot as plt
from matplotlib.widgets import CheckButtons
colourax = plt.axes([0.5, 0.4, 0.09, 0.2])
colours = CheckButtons(colourax, ('Red', 'Green', 'Blue'), (False, False, False))
isRedChecked = colours.lines[0][0].get_visible()
isGreenChecked = colours.lines[1][0].get_visible()
isBlueChecked = colours.lines[2][0].get_visible()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With