lundi 9 novembre 2020

Add checkbox in python chart legend

I need to add a checkbox to a python chart, to check the lines to be displayed or hidden.

I found the code below that works just fine, except one detail, that is annoyingly difficult for me to find out, I already have a few weeks since I am trying to do that: besides the checkboxes and the series names, I would like to also have the line colors along to the text, to be able to visually identify which line is which series.

Initially I tried to show the legend over the text, next to the checkboxes, but the legend would move if the window is resized, and that would not be feasible to implement.

My feeling is that there should be a way to add the line colors display within the function that creates the checkboxes, can anyone give me some suggestions on how to do that? The function is:

def func(label):
    index = labels.index(label)
    lines[index].set_visible(not lines[index].get_visible())
    plt.draw()

The link with the full code is:

https://matplotlib.org/3.1.0/gallery/widgets/check_buttons.html




Aucun commentaire:

Enregistrer un commentaire