Skip to content

Instantly share code, notes, and snippets.

@samredai
Created August 13, 2020 04:57
Show Gist options
  • Save samredai/f736511579d69b9eb8b393b53d54f410 to your computer and use it in GitHub Desktop.
Save samredai/f736511579d69b9eb8b393b53d54f410 to your computer and use it in GitHub Desktop.
Python: Add a manager to a matplotlib FigureCanvasBase object
def add_manager(fig):
"""
Adds a manager to a FigureCanvasBase instance to enable show method
Example:
>>> from matplotlib.figure import Figure
>>> fig = Figure(figsize=(10, 10))
>>> ax = fig.add_subplot(1, 1, 1)
>>> ax.set_title("Example axis")
>>> add_manager(fig)
>>> fig.show()
"""
empty_fig = plt.figure()
manager = empty_fig.canvas.manager
manager.canvas.figure = fig
fig.set_canvas(manager.canvas)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment