Is there a way to set the logical status of CheckButtons in matplotlib withput triggering onclick()
callbacks?
Here is my scenario:
I am displaying a graph with a large number of traces (50+) and want to give the user the option of displaying a subset of these on the basis of some fixed queries, which the user selects via CheckButton
. Every time a button is clicked the the script gets the status of all present CheckButton
s via get_status()
, computes the indices of the traces that meet the selected criteria, and updates the display accordingly.
In order to make life easier for the user I want to also have a "Select all" and "Clear all" buttons. The best way I can come up with to implement these is to force the logical state of all CheckButtons to True or False without triggering an on_click()
callback, then set the visibility of the traces accordingly.
However, CheckButton()
does not have a set_status()
method
https://matplotlib.org/api/widgets_api.html#matplotlib.widgets.CheckButtons
There is a set_active()
method but according the documetnation it triggers a callback if eventson
is true.
Can someone give me a couple of pointers how to go about doing this? Do I need to set eventson=False
for the wdget, then set_active()=True
followed by eventson=True
? Seems rather clunky, but I can't figure a more elegant way, even after spending way too many hours.
Thanks!
I knew it, as soon as I post a question I figure out the answer. Here is what I came up with for anyone else that wants to do something like this
here check is a reference to the
CheckBox()
object andenable
is a variable set toTrue
if you want to enable all checkboxes, orFalse
otherwise.