如何显示未使用pyplot / pylab figure()创建的数字,但是直接从matplotlib的Figure类构建?
import matplotlib as mpl
figure = mpl.figure.Figure()
figure.show() # this won't work
答案 0 :(得分:1)
示例代码(基于类的演示)发布在https://stackoverflow.com/a/25769600/3666197
中原则通过
起作用class SuperShapeFrame( Frame ): # The user interface:
其中MVC-Controller UI交互和MVC-Model输出都被重新处理,并且 Figure 对象的结果输出状态被发送到MVC-Visual部分(由<处理< kbd> FigureCanvasTkAgg object,.grid()
- 装入Tkinter)
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
有关完整来源,请使用上面的链接
答案 1 :(得分:0)
使用pyplot / pylab figure()创建但未直接从matplotlib构建的图类需要一个图形管理器:
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_tkagg.new_figure_manager_given_figure()
函数也可以这样做,但我的python-matplotlib
版本(1.1.1~rc1 + git20120423-0ubuntu1)中尚不存在该函数。