我有一个我在 matplotlib 中制作的漂亮球体。我将如何将它放入 tkinter 框架小部件中?能够将它集成到现有的 tkinter GUI 中会很好。也可以去掉显示屏下方的菜单栏吗?我不需要保存输出或缩放,所以对我来说没用。
from mpl_toolkits.mplot3d import axes3d,Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
fig = plt.figure()
ax = Axes3D(fig) #<-- Note the difference from your original code..
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
x = 10 * np.outer(np.cos(u), np.sin(v))
y = 10 * np.outer(np.sin(u), np.sin(v))
z = 10 * np.outer(np.ones(np.size(u)), np.cos(v))
ax.plot_surface(x, y, z, rstride=4, cstride=4, color='lightgreen',linewidth=0)
#,antialiased=False
#cmap=cm.jet
plt.show()
最佳答案
查看在 tk GUI 中嵌入绘图的示例,它应该足以让您朝着正确的方向开始。
user_interfaces example code: embedding_in_tk.py
user_interfaces example code: embedding_in_tk2.py
至于工具栏的删除,是在GUI中嵌入绘图时不添加的情况。
If you are using matplotlib.pyplot the toolbar will be created automatically for every figure. If you are writing your own user interface code, you can add the toolbar as a widget.
关于python - 在 tkinter 中运行 matplotlib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3845407/