python - 在 tkinter 中运行 matplotlib

标签 python matplotlib tkinter

我有一个我在 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/

相关文章:

python - 安装和导入 SendKeys 时出现问题 -- 更新

python - 使用 Pandas 读取无分隔符的文件

python - 在多进程中无法更新 QTextEdit

python - Matplotlib - 轴的不同边缘的 mark_inset

python - ImportError DLL 加载失败导入 _tkinter

python - 如何在 Python 中使用 OpenCV 检测行上方的文本

python - 尝试使用 matplotlib 绘制 OpenCV 的 MSER 区域

python - Python 中给定 r、theta 和 z 值的极坐标直方图

python - 如何使用 tkinter 在每个循环中重复获取文本小部件的内容?

python - TclError : no display name and no $DISPLAY environment variable in Google Colab