Created
August 13, 2020 04:57
-
-
Save samredai/f736511579d69b9eb8b393b53d54f410 to your computer and use it in GitHub Desktop.
Python: Add a manager to a matplotlib FigureCanvasBase object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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