You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.2 KiB
46 lines
1.2 KiB
1 year ago
|
import tkinter as tk
|
||
|
|
||
|
import numpy as np
|
||
|
from matplotlib import pyplot as plt
|
||
|
from matplotlib.figure import Figure
|
||
|
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
|
||
|
from mpl_toolkits.mplot3d import Axes3D
|
||
|
import sympy
|
||
|
from numpy import arange
|
||
|
|
||
|
|
||
|
def plot_3d_graph():
|
||
|
# 创建一个 Figure 对象
|
||
|
fig = Figure(figsize=(8, 8), dpi=100, facecolor='#cdcdcd', edgecolor="#cdcdcd")
|
||
|
x = arange(-19, 20, 0.1)
|
||
|
y = arange(-19, 20, 0.1)
|
||
|
z = []
|
||
|
sympy.Symbol("x y")
|
||
|
for i in arange(-19, 20, 0.1):
|
||
|
z.append(sympy.sympify("x**2+y**2").subs("x", i).subs("y", i).evalf())
|
||
|
# 在 Figure 上创建一个 3D 子图
|
||
|
ax = fig.add_subplot(111, projection='3d')
|
||
|
ax.plot3D(x, y, z, 'gray')
|
||
|
|
||
|
# 绘制三维图形
|
||
|
# 在这里添加你自己的三维图形绘制逻辑
|
||
|
# 例如 ax.plot_surface() 或 ax.scatter()
|
||
|
|
||
|
# 创建一个 tkinter 窗口
|
||
|
root = tk.Tk()
|
||
|
root.title("3D Graph")
|
||
|
|
||
|
# 在 tkinter 窗口上创建一个 canvas
|
||
|
canvas = FigureCanvasTkAgg(fig, master=root)
|
||
|
canvas.draw()
|
||
|
canvas.get_tk_widget().pack()
|
||
|
|
||
|
# 运行 tkinter 主循环
|
||
|
tk.mainloop()
|
||
|
|
||
|
|
||
|
# 调用函数绘制三维图形
|
||
|
plot_3d_graph()
|
||
|
|
||
|
|