在 tkinter 中运行 matplotlib
我有一个用 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()
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看一下在 tk GUI 中嵌入绘图的示例,它应该足以让您朝着正确的方向开始。
用户界面示例代码:embedding_in_tk.py
user_interfaces 示例代码:embedding_in_tk2.py
至于删除工具栏,是在 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.
user_interfaces example code: embedding_in_tk.py
user_interfaces example code: embedding_in_tk2.py
As for removing the toolbar, it's a case of not adding it when you are embedding plots in a GUI.