MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _get_renderer

Function _get_renderer

lib/matplotlib/backend_bases.py:1597–1626  ·  view source on GitHub ↗

Get the renderer that would be used to save a `.Figure`. If you need a renderer without any active draw methods use renderer._draw_disabled to temporary patch them out at your call site.

(figure, print_method=None)

Source from the content-addressed store, hash-verified

1595
1596
1597def _get_renderer(figure, print_method=None):
1598 """
1599 Get the renderer that would be used to save a `.Figure`.
1600
1601 If you need a renderer without any active draw methods use
1602 renderer._draw_disabled to temporary patch them out at your call site.
1603 """
1604 # This is implemented by triggering a draw, then immediately jumping out of
1605 # Figure.draw() by raising an exception.
1606
1607 class Done(Exception):
1608 pass
1609
1610 def _draw(renderer): raise Done(renderer)
1611
1612 with cbook._setattr_cm(figure, draw=_draw), ExitStack() as stack:
1613 if print_method is None:
1614 fmt = figure.canvas.get_default_filetype()
1615 # Even for a canvas' default output type, a canvas switch may be
1616 # needed, e.g. for FigureCanvasBase.
1617 print_method = stack.enter_context(
1618 figure.canvas._switch_canvas_and_return_print_method(fmt))
1619 try:
1620 print_method(io.BytesIO())
1621 except Done as exc:
1622 renderer, = exc.args
1623 return renderer
1624 else:
1625 raise RuntimeError(f"{print_method} did not call Figure.draw, so "
1626 f"no renderer is available")
1627
1628
1629def _no_output_draw(figure):

Callers 3

_get_rendererMethod · 0.90
print_figureMethod · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…