在tkinter中运行matplotlib [英] Running matplotlib in tkinter

查看:89
本文介绍了在tkinter中运行matplotlib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用matplotlib制作的美丽球体.我如何将其放入tkinter框架小部件中?能够将其集成到现有的tkinter GUI中非常好.还可以摆脱显示器下方的菜单栏吗?我不需要保存输出或缩放,因此对我来说毫无用处.

I have this beautiful sphere I made in matplotlib. How would I go about putting it in a tkinter frame widget? It'd be nice to be able to integrate it into an existing tkinter GUI. Also is it possible to rid of the menu bar below the display? I have no need to save the output or zoom, so it's useless to me.

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中嵌入绘图的示例,这足以使您朝正确的方向开始.

Have a look at the examples for embedding plots in a tk GUI, it should be enough to get you started in the right direction.

用户界面示例代码:embedding_in_tk.py

用户界面示例代码:embedding_in_tk2.py

关于删除工具栏,是在将图形嵌入GUI时不添加工具栏的情况.

As for removing the toolbar, it's a case of not adding it when you are embedding plots in a GUI.

如果您使用的是matplotlib.pyplot 工具栏将自动创建 每个数字.如果你在写 您自己的用户界面代码,您可以 将工具栏添加为小部件.

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.

这篇关于在tkinter中运行matplotlib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆