Python Forum
[Tkinter] cutomtkinter matplotlib no x,y - xaxis and x,y - labels-> only graph and grid visible
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] cutomtkinter matplotlib no x,y - xaxis and x,y - labels-> only graph and grid visible
#1
I am trying to create a virtual signal-generator(function-generator) - GUI with the cutomtkinter, matplotlib libs. The graph should be updated after a button click continuosly. I have managed to get a graph updated continuosly with a grid in the backround, but the x,y - xaxis and x,y - labels are not visible?

Here is the button code:

    def update_window(self):
        startx, endx = 0, SIG_ARRAY_SIZE + 1
        starty, endy = -SIG_ARRAY_DEFAULT_AMPLITUDE - 1, SIG_ARRAY_DEFAULT_AMPLITUDE + 1
        plt.axis([startx, endx, starty, endy])
        plt.xlabel('t [msec]')
        plt.ylabel('U [V]')
        fig, ax = plt.subplots()
        ax = fig.add_subplot(111)

        while True:
            fig, ax = plt.subplots()
            ax.set_title('Signal')
            plt.axis([startx, endx, starty, endy])
            ax.set_xlabel('t [msec]', fontweight=12)
            ax.set_ylabel('U [V]', fontsize=12)

            x_val: list = list(range(0, SIG_ARRAY_SIZE, 1))
            # generating random data values
            sig.sigSetSignalName("Sinus")
            sig.sigCreateSinusSignal()
            y_val = sig.sig_arr

            ax.axis([startx, endx, starty, endy])
            ax.grid()

            line, = plt.plot(x_val, y_val, 'b')

            fig.subplots_adjust(left=0, right=1, bottom=0, top=1, wspace=0, hspace=0)
            canvas = FigureCanvasTkAgg(fig, master=self.root)
            canvas.draw()
            canvas.get_tk_widget().place(relx=0.33, rely=0.025)

            plt.close(fig)
            self.root.update()
Here is a snapshot of the GUI:
   
';" src="
   
" alt="İmage" id="maximage" title="Click Photo To Enlarge">


Here is the code of the whole module:
from  signal_generator import SignalGenerator
import tkinter as tk
import customtkinter as ctk
from tkinter import Button
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from operator import methodcaller
import time


SIG_ARRAY_SIZE = 360
SIG_ARRAY_DEFAULT_VALUE = 5
SIG_ARRAY_DEFAULT_AMPLITUDE = 10

sig: SignalGenerator = SignalGenerator()

class ctkApp:

    def __init__(self):
        ctk.set_appearance_mode("dark")
        self.root = ctk.CTk()
        self.root.geometry("1000x600+200x200")
        self.root.title("Signal Scope")
        self.root.update()
        self.frame = ctk.CTkFrame(master=self.root,
                                  height=self.root.winfo_height() * 0.95,
                                  width=self.root.winfo_width() * 0.66,
                                  fg_color="darkblue")
        self.frame.place(relx=0.33, rely=0.025)
        self.input = ctk.CTkEntry(master=self.root,
                                  placeholder_text=100,
                                  justify='center',
                                  width=300,
                                  height=50,
                                  fg_color="darkblue")
        self.input.insert(0, 100)
        self.input.place(relx=0.025, rely=0.5)
        self.slider = ctk.CTkSlider(master=self.root,
                                    width=300,
                                    height=20,
                                    from_=1,
                                    to=1000,
                                    number_of_steps=999,
                                    command=self.update_surface)
        self.slider.place(relx=0.025, rely=0.75)
        self.button = ctk.CTkButton(master=self.root,
                                    text="Update Graph",
                                    width=300,
                                    height=50,
                                    command=self.update_window)
        self.button.place(relx=0.025, rely=0.25)
        self.root.mainloop()

    def update_window(self):
        startx, endx = 0, SIG_ARRAY_SIZE + 1
        starty, endy = -SIG_ARRAY_DEFAULT_AMPLITUDE - 1, SIG_ARRAY_DEFAULT_AMPLITUDE + 1
        plt.axis([startx, endx, starty, endy])
        plt.xlabel('t [msec]')
        plt.ylabel('U [V]')
        fig, ax = plt.subplots()
        ax = fig.add_subplot(111)

        while True:
            fig, ax = plt.subplots()
            ax.set_title('Signal')
            plt.axis([startx, endx, starty, endy])
            ax.set_xlabel('t [msec]', fontweight=12)
            ax.set_ylabel('U [V]', fontsize=12)

            x_val: list = list(range(0, SIG_ARRAY_SIZE, 1))
            # generating random data values
            sig.sigSetSignalName("Sinus")
            sig.sigCreateSinusSignal()
            y_val = sig.sig_arr

            ax.axis([startx, endx, starty, endy])
            ax.grid()

            line, = plt.plot(x_val, y_val, 'b')

            fig.subplots_adjust(left=0, right=1, bottom=0, top=1, wspace=0, hspace=0)
            canvas = FigureCanvasTkAgg(fig, master=self.root)
            canvas.draw()
            canvas.get_tk_widget().place(relx=0.33, rely=0.025)

            plt.close(fig)
            self.root.update()

    def update_surface(self, other):

            fig, ax = plt.subplots()
            fig.set_size_inches(11, 5.3)
            ax.scatter(x, y, s * self.slider.get(), c)
            ax.axis("off")
            fig.subplots_adjust(left=0, right=1, bottom=0, top=1, wspace=0, hspace=0)
            canvas = FigureCanvasTkAgg(fig, master=self.root)
            canvas.draw()
            canvas.get_tk_widget().place(relx=0.33, rely=0.025)
            self.root.update()



if __name__ == "__main__":
    CTK_Window = ctkApp()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Tkinter Matplotlib Animation Graph not rendering dimidgen 3 549 Mar-12-2024, 02:09 PM
Last Post: deanhystad
  [Tkinter] how to make label or button not visible with the place method? nowayj63 2 2,793 Jan-03-2023, 06:29 PM
Last Post: Yoriz
  [PyQt] Determine whether text in QTableView cell is fully visible or not random_nick 0 982 Oct-27-2022, 09:29 PM
Last Post: random_nick
  [PyQt] Refresh x-labels in matplotlib animation widget JohnT 5 3,750 Apr-23-2021, 07:40 PM
Last Post: JohnT
  Dynamic graph matplotlib quant7 1 4,112 May-17-2019, 06:24 PM
Last Post: quant7
  How to show graph as a slideshow in PyQt5 using matplotlib binsha 0 3,905 Mar-08-2019, 03:58 AM
Last Post: binsha
  Plotting Matplotlib Grid Lines gehrenfeld 12 5,945 Feb-23-2019, 12:37 AM
Last Post: gehrenfeld

Forum Jump:

User Panel Messages

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