Python 如何显示直接从地物类创建的matplotlib地物?

Python 如何显示直接从地物类创建的matplotlib地物?,python,matplotlib,plot,Python,Matplotlib,Plot,如何显示不是使用pyplot/pylab figure()创建的图形,而是直接从matplotlib的figure类构造的图形 import matplotlib as mpl figure = mpl.figure.Figure() figure.show() # this won't work 未使用pyplot/pylab figure()创建但直接从matplotlib的figure类构造的地物需要地物管理器: import Tkinter as Tk import matplotli

如何显示不是使用pyplot/pylab figure()创建的图形,而是直接从matplotlib的figure类构造的图形

import matplotlib as mpl
figure = mpl.figure.Figure()
figure.show() # this won't work

未使用pyplot/pylab figure()创建但直接从matplotlib的figure类构造的地物需要地物管理器:

import Tkinter as Tk
import matplotlib as mpl
import matplotlib.backends.backend_tkagg as tkagg

figure = mpl.figure.Figure()

window = Tk.Tk()
canvas = tkagg.FigureCanvasTkAgg(figure, master=window)
figManager = tkagg.FigureManagerTkAgg(canvas, 0, window)
figManager.show()
使用
backend\u tkagg.new\u figure\u manager\u given\u figure()
函数也可以实现这一点,但在我的
python matplotlib
(1.1.1~rc1+git2020423-0ubuntu1)版本中还不存在该函数。

直接图形/Tkinter协同集成 示例代码(基于类的演示)发布在

原理是通过一个

class SuperShapeFrame( Frame ):                                         # The user interface:
其中MVC控制器UI交互和MVC模型输出都被重新处理,图形对象的结果输出状态被发送到MVC可视部件(由安装在Tkinter中的FigureCanvasTkAgg对象处理,
.grid()


对于完整的源代码,请使用上面的链接,遗憾的是,该函数实际上仍然依赖于pyplot。我建议您升级mpl,我们现在使用的是v1.4.0
self.fig        = Figure( ( 6, 6 ), dpi = 100 )                         # matplotlib side
canvas          = FigureCanvasTkAgg( self.fig, master = self )          # canvas
canvas.get_tk_widget().grid( row = 0, column = 0, columnspan = 4 )      # grid()-ed into Tkinter