2

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 CheckButtons 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!

1 Answer 1

4

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

    check.eventson = False
    status = check.get_status()
    for i,stat in enumerate(status):
        if ((enable and not stat) or (not enable and stat)): 
            check.set_active(i)
    check.eventson = True

here check is a reference to the CheckBox() object and enable is a variable set to True if you want to enable all checkboxes, or False otherwise.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.