How to display figures that were not created using pyplot/pylab figure(), but constructed directly from matplotlib's Figure class?
import matplotlib as mpl
figure = mpl.figure.Figure()
figure.show() # this won't work
How to display figures that were not created using pyplot/pylab figure(), but constructed directly from matplotlib's Figure class?
import matplotlib as mpl
figure = mpl.figure.Figure()
figure.show() # this won't work
Sample code ( Class-based demo ) is posted in https://stackoverflow.com/a/25769600/3666197
Principle works via a
class SuperShapeFrame( Frame ): # The user interface:
where both an MVC-Controller UI-interactions and an MVC-Model outputs are re-processed and the resulting output state of a Figure object is sent to MVC-Visual part ( handled by a FigureCanvasTkAgg object, .grid()
-mounted into 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
For the full source, use the link above
Figures that were not created using pyplot/pylab figure() but constructed directly from matplotlib's Figure class need a figure manager:
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()
This might also be doable using backend_tkagg.new_figure_manager_given_figure()
function, but that function does not yet exist in my version of python-matplotlib
(1.1.1~rc1+git20120423-0ubuntu1).