Thanks to visit codestin.com
Credit goes to github.com

Skip to content

"Fix" tight_layout for template backend. #17731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 11 additions & 4 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,6 @@ def _get_renderer(figure, print_method=None):

If you need a renderer without any active draw methods use
renderer._draw_disabled to temporary patch them out at your call site.

"""
# This is implemented by triggering a draw, then immediately jumping out of
# Figure.draw() by raising an exception.
Expand All @@ -1545,15 +1544,23 @@ class Done(Exception):
def _draw(renderer): raise Done(renderer)

with cbook._setattr_cm(figure, draw=_draw):
orig_canvas = figure.canvas
if print_method is None:
fmt = figure.canvas.get_default_filetype()
print_method = getattr(figure.canvas, f"print_{fmt}")
# Even for a canvas' default output type, a canvas switch may be
# needed, e.g. for FigureCanvasBase.
print_method = getattr(
figure.canvas._get_output_canvas(None, fmt), f"print_{fmt}")
try:
print_method(io.BytesIO(), dpi=figure.dpi)
except Done as exc:
renderer, = figure._cachedRenderer, = exc.args

return renderer
return renderer
else:
raise RuntimeError(f"{print_method} did not call Figure.draw, so "
f"no renderer is available")
finally:
figure.canvas = orig_canvas


def _is_non_interactive_terminal_ipython(ip):
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/backends/backend_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def print_foo(self, filename, *args, **kwargs):
to their original values after this call, so you don't need to
save and restore them.
"""
self.draw()

def get_default_filetype(self):
return 'foo'
Expand Down