我正在嘗試使用matplotlib在tkinter窗口中繪製一個球體。我如何去做顯示廣場?我希望球體儘可能少地失真。在Tkinter中嵌入Matplotlib,顯示問題
我的代碼:
#!/usr/bin/env python
import matplotlib
matplotlib.use('TkAgg')
from mpl_toolkits.mplot3d import axes3d,Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
from numpy import arange, sin, pi
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
import Tkinter
import sys
class ElectronOrbitalGenerator(Tkinter.Tk):
def __init__(self,parent):
Tkinter.Tk.__init__(self,parent)
self.parent = parent
self.protocol("WM_DELETE_WINDOW", self.dest)
self.main()
def main(self):
self.fig = plt.figure()
ax = Axes3D(self.fig)
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))
t = ax.plot_surface(x, y, z, rstride=4, cstride=4, color='lightgreen',linewidth=0)
self.frame = Tkinter.Frame(self)
self.frame.pack(padx=15,pady=15)
self.canvas = FigureCanvasTkAgg(self.fig, master=self.frame)
self.canvas.get_tk_widget().pack(side='top', fill='both', expand=1)
self.canvas._tkcanvas.pack(side='top', fill='both', expand=1)
self.btn = Tkinter.Button(self,text='button',command=self.alt)
self.btn.pack()
def alt (self):
print 9
def dest(self):
self.destroy()
sys.exit()
if __name__ == "__main__":
app = ElectronOrbitalGenerator(None)
app.title('Embedding in TK')
app.mainloop()
編輯
我試圖
,並得到這個
AttributeError: 'Figure' object has no attribute 'set_figheigth'
我有一個錯字,它是:set_figheight – tillsten 2010-10-03 20:19:02