如何显示不是使用pyplot / pylab fig()创建,而是直接从matplotlib的Figure类构造的图形?
import matplotlib as mpl
figure = mpl.figure.Figure()
figure.show() # this won't work
最佳答案
不是使用pyplot / pylab fig()创建的图,而是直接从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_tkagg.new_figure_manager_given_figure()
函数也可能可行,但是该函数在我的python-matplotlib
版本(1.1.1〜rc1 + git20120423-0ubuntu1)中尚不存在。关于python - 如何显示直接从Figure类创建的matplotlib图?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25953356/