dimanche 7 février 2021

How to sum multiple column data using checkbox in tkinter GUI and plot the resultant column data

Currently I am building a tkinter GUI. I am stuck in the following problem: I need to sum the columns of dataset row wise( for example column 1+column 2+column 3=new column) using tkinter checkbox option and then plot the summed column as a line graph. I need help understanding how to sum the column data by selecting columns using checkbox and the n plot it. My code is given below :

def check():
    global feat
    feat_names = list(data2.columns)
    checkboxes = []
    for i in range(len(feat_names)):
        feat = tk.StringVar()
        check_box = tk.Checkbutton(root, text=feat_names[i], variable=feat, state ='normal')
        checkboxes.append(check_box)
        check_box.grid(column=5, row=i+2, sticky=tk.W)         
        check_box.deselect()
    return feat
        

def plotsum():
    for item in data2:
        x, w = data2['Load'], data2[feat.get()]
        fig = Figure(figsize=(5, 5))
        plt.plot(x, w)
        plt.ylabel(feat.get())
        plt.xlabel("Load")
        canvas = FigureCanvasTkAgg(fig, master=chart_frame)
        canvas.get_tk_widget().grid(row=0, column=0)
    canvas.draw()
    toolbar_frame = Frame(plot_frame)
    toolbar_frame.grid(row=1, column=0)
    toolbar = NavigationToolbar2Tk(canvas, toolbar_frame)
    toolbar.update()
    plt.show()




Aucun commentaire:

Enregistrer un commentaire