Я новичок в Python и пытаюсь научиться сочетать tkinter и matplotlib. У меня есть код, который отображает функцию треугольника при нажатии кнопки и отображает функцию ловушки при нажатии второй кнопки. Как я могу сделать так, чтобы при нажатии обеих кнопок обе функции отображались на одном графике? Есть ли у кого-нибудь опыт работы с этой темой?
Заранее спасибо.
from tkinter import *
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg,
NavigationToolbar2Tk)
import customtkinter as ctk
import numpy as np
def plot(MF):
fig = Figure()
plot1= fig.add_subplot(111)
fig.set_facecolor("grey")
fig.set_edgecolor("blue")
plot1.plot(MF)
canvas = FigureCanvasTkAgg(fig, win)
canvas.draw()
toolbar = NavigationToolbar2Tk(canvas, win)
toolbar.update()
toolbar.place(relx=0.2, rely=0.4)
canvas.get_tk_widget().place(relx=0.05, rely=0.4)
def Triangle_function():
a = 100
b = 500
c = 700
MF = np.zeros(1000)
for x in range(1000):
if x < a:
MF[x] = 0
elif x >= a and x = b and x c:
MF[x] = 0
plot (MF)
def Trapz():
a = 100
b = 500
c = 700
d = 900
MF = np.zeros(1000)
for x in range(1000):
if x < a:
MF[x] = 0
elif x >= a and x < b:
MF[x] = (x-a)/(b-a)
elif x >= b and x < c:
MF[x] = 1
elif x >= c and x < d:
MF[x] = (d-x)/(d-c)
elif x >= d:
MF[x] = 0
plot(MF)
win = ctk.CTk()
win.geometry("1000x1000")
win.title("Fuzzy Logic Designer")
win.resizable(False, False)
plot_Button = ctk.CTkButton(win, text="plot", command = Triangle_function)
plot_Button.pack()
plot_Button1 = ctk.CTkButton(win, text="plot", command = Trapz)
plot_Button1.pack(pady=20)
win.mainloop()
Подробнее здесь: https://stackoverflow.com/questions/782 ... matplotlib