Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ENH: new backend function to fabricate a fully operational figure
  • Loading branch information
tacaswell committed Oct 31, 2020
commit 7dd08a8f7dfd9575ec9c0605702c235dc7b49e0d
33 changes: 33 additions & 0 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3537,6 +3537,38 @@ def new_figure_manager_given_figure(cls, num, figure):
manager = cls.FigureManager(canvas, num)
return manager

@classmethod
def new_figure(cls, label='Matplotlib Figure', *, auto_redraw=True):
"""
Create a new window with a Figure and toolbar

Parameters
----------
label : str
Use for the window title and figure label.

auto_redraw : bool
If the figure should automatically re-draw when stale.
"""
manager = cls.new_figure_manager(label)
manager.canvas.figure.set_label(label)

def redraw(fig, val):
canvas = fig.canvas
if val and not canvas.is_saving() and not canvas._is_idle_drawing:
# Some artists can mark themselves as stale in the
# middle of drawing (e.g. axes position & tick labels
# being computed at draw time), but this shouldn't
# trigger a redraw because the current redraw will
# already take them into account.
with fig.canvas._idle_draw_cntx():
fig.canvas.draw_idle()

if auto_redraw:
manager.canvas.figure.stale_callback = redraw

return manager.canvas.figure

@classmethod
def draw_if_interactive(cls):
if cls.trigger_manager_draw is not None and is_interactive():
Expand Down Expand Up @@ -3590,6 +3622,7 @@ def export(cls):
"FigureManager",
"new_figure_manager",
"new_figure_manager_given_figure",
"new_figure",
"draw_if_interactive",
"show",
]:
Expand Down