Python Forum
Showing an empty chart, then input data via function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Showing an empty chart, then input data via function
#1
Hello.

I have been able to create a chart with the data I am looking for via button click/function. The chart only shows after I click on the button to run a function. I am hoping to have an empty chart sitting in my widget, then once the function is called the chart data is placed on the chart. Below is the code I am using.


Thanks for your suggestions

class Page3(tk.Frame):
    def __init__(self, master, **kw):
        super().__init__(master, **kw)
        self.config(background='black')

        def graph_data():

            last_name = n_entry.get()
            #Connect to sqlite and grab the data for the last_name variable above not shown...


            categories = ['Sleep', 'Fatigue', 'Soreness', 'Stress', 'Mood', 'Diet', 'RPE', 'Sleep']
            categories2 = ['Sleep', 'Fatigue', 'Soreness', 'Stress', 'Mood', 'Diet', 'RPE']
            lbls = [0., 0.8975979,  1.7951958,  2.6927937,  3.5903916,  4.48798951, 5.38558741]
            graph = [sle, fat, sor, ste, moo, die, rpe, sle]
            others = [t_sle, t_fat, t_sor, t_ste, t_moo, t_die, t_rpe, t_sle]

            label_loc = np.linspace(start=0, stop=2 * np.pi, num=len(categories))

            fig = plt.figure(figsize=(10, 9), dpi=40, facecolor='#2E2E2E')
            ax = plt.subplot(polar=True)
            plt.plot(label_loc, graph, label='Name', color='#3769b9')
            plt.fill(label_loc, others, color='#D23C1E', alpha=.25)
            plt.plot(label_loc, others, label='team', color='#D23C1E')
            plt.title('Metrics', size=40, color='white')
            ax.set_yticklabels([])
            ax.set_ylim(0, max(graph) +.1)
            ax.set_facecolor('#2E2E2E')
            plt.legend(loc='upper left')
            plt.subplots_adjust(left=0.05, bottom=0.05, right=0.92, top=0.90)
            plt.thetagrids(np.degrees(lbls), categories2, size=20, color='white')
            for label, angle in zip(ax.get_xticklabels(), label_loc):
                if.1 < angle < 1:
                    label.set_horizontalalignment('left')
                    label.set_verticalalignment('bottom')
                elif 1.1 < angle < 2:
                    label.set_horizontalalignment('right')
                    label.set_verticalalignment('bottom')
                elif 2.1 < angle < 3:
                    label.set_horizontalalignment('right')
                    label.set_verticalalignment('bottom')
                elif 3.1 < angle < 4:
                    label.set_horizontalalignment('right')
                    label.set_verticalalignment('top')
                elif 4.1 < angle < 5:
                    label.set_horizontalalignment('right')
                    label.set_verticalalignment('top')
                elif 4.1 < angle < 5:
                    label.set_horizontalalignment('right')
                    label.set_verticalalignment('top')
                elif 4.1 < angle < 5:
                    label.set_horizontalalignment('left')
                    label.set_verticalalignment('top')
                else:
                    label.set_horizontalalignment('left')

            canvas = FigureCanvasTkAgg(fig, master=graph_frame)
            canvas.get_tk_widget().pack(anchor=E)
            canvas.draw()

        button_frame = LabelFrame(self, background='#2E2E2E')
        button_frame.pack(fill='x', expand=YES, padx=20, pady=20, anchor='n')

        n_label = Label(button_frame, text="Name", background='#2E2E2E')
        n_label.grid(row=0, column=1, padx=10, pady=10)
        n_entry = Entry(button_frame)
        n_entry.grid(row=0, column=2, pady=10)
        
        graph_frame = LabelFrame(self, background='#2E2E2E')
        graph_frame.pack(fill='x', expand=YES, padx=20, pady=10, anchor=S)

        g_button = Button(graph_frame, text="show graph", command=graph_data)
        g_button.pack()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with to check an Input list data with a data read from an external source sacharyya 3 417 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  difference between forms of input a list to function akbarza 6 1,043 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  manually input data jpatierno 0 346 Nov-10-2023, 02:32 AM
Last Post: jpatierno
  Input network device connection info from data file edroche3rd 6 1,062 Oct-12-2023, 02:18 AM
Last Post: edroche3rd
  how do you style data frame that has empty rows. gsaray101 0 536 Sep-08-2023, 05:20 PM
Last Post: gsaray101
Question in this code, I input Key_word, it can not find although all data was exact Help me! duchien04x4 3 1,055 Aug-31-2023, 05:36 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,103 Dec-25-2022, 03:00 PM
Last Post: askfriends
  Same Data Showing Several Times With Beautifulsoup Query eddywinch82 2 1,256 May-29-2022, 11:46 PM
Last Post: eddywinch82
Question Change elements of array based on position of input data Cola_Reb 6 2,143 May-13-2022, 12:57 PM
Last Post: Cola_Reb
  Showing data change korenron 10 2,581 Mar-20-2022, 01:50 PM
Last Post: korenron

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020