import numpy as np
import matplotlib.pyplot as plt
from tkinter import *
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
# 역삼각 함수 그래프 그리기 함수
def plot_graph():
func_type = function_var.get()
start = float(entry_start.get())
end = float(entry_end.get())
x = np.linspace(start, end, 400)
if func_type == 'arcsin':
y = np.arcsin(np.clip(x, -1, 1)) # arcsin의 입력은 [-1, 1]로 제한
elif func_type == 'arccos':
y = np.arccos(np.clip(x, -1, 1)) # arccos의 입력은 [-1, 1]로 제한
elif func_type == 'arctan':
y = np.arctan(x)
else:
return
fig = plt.Figure(figsize=(5, 5), dpi=100)
ax = fig.add_subplot(111)
ax.plot(x, y)
ax.set_title(f'{func_type} Graph')
canvas = FigureCanvasTkAgg(fig, master=window)
canvas.draw()
canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=True)
# GUI 생성
window = Tk()
window.title("Inverse Trigonometric Function Plotter")
# 함수 선택 라벨 및 드롭다운
label_func = Label(window, text="Choose a function:")
label_func.pack()
function_var = StringVar(window)
function_var.set("arcsin") # 기본값
function_menu = OptionMenu(window, function_var, "arcsin", "arccos", "arctan")
function_menu.pack()
# 범위 입력 라벨 및 입력창
label_start = Label(window, text="Enter start value:")
label_start.pack()
entry_start = Entry(window)
entry_start.pack()
label_end = Label(window, text="Enter end value:")
label_end.pack()
entry_end = Entry(window)
entry_end.pack()
# 그래프 그리기 버튼
button_plot = Button(window, text="Plot", command=plot_graph)
button_plot.pack()
window.mainloop()