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

Skip to content

Commit 15a62c1

Browse files
committed
ENH: promote no output to figure level
1 parent c6bfb7c commit 15a62c1

File tree

6 files changed

+18
-17
lines changed

6 files changed

+18
-17
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,9 +1584,9 @@ def _draw(renderer): raise Done(renderer)
15841584

15851585

15861586
def _no_output_draw(figure):
1587-
renderer = _get_renderer(figure)
1588-
with renderer._draw_disabled():
1589-
figure.draw(renderer)
1587+
# _no_output_draw was promoted to the figure level, but
1588+
# keep this here in case someone was calling it...
1589+
figure.draw_no_output()
15901590

15911591

15921592
def _is_non_interactive_terminal_ipython(ip):

lib/matplotlib/backends/backend_pdf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from matplotlib._pylab_helpers import Gcf
3030
from matplotlib.backend_bases import (
3131
_Backend, _check_savefig_extra_args, FigureCanvasBase, FigureManagerBase,
32-
GraphicsContextBase, RendererBase, _no_output_draw)
32+
GraphicsContextBase, RendererBase)
3333
from matplotlib.backends.backend_mixed import MixedModeRenderer
3434
from matplotlib.figure import Figure
3535
from matplotlib.font_manager import findfont, get_font
@@ -2718,7 +2718,7 @@ def print_pdf(self, filename, *,
27182718
file.close()
27192719

27202720
def draw(self):
2721-
_no_output_draw(self.figure)
2721+
self.figure.draw_no_output()
27222722
return super().draw()
27232723

27242724

lib/matplotlib/backends/backend_pgf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from matplotlib import _api, cbook, font_manager as fm
2020
from matplotlib.backend_bases import (
2121
_Backend, _check_savefig_extra_args, FigureCanvasBase, FigureManagerBase,
22-
GraphicsContextBase, RendererBase, _no_output_draw
22+
GraphicsContextBase, RendererBase
2323
)
2424
from matplotlib.backends.backend_mixed import MixedModeRenderer
2525
from matplotlib.backends.backend_pdf import (
@@ -889,7 +889,7 @@ def get_renderer(self):
889889
return RendererPgf(self.figure, None)
890890

891891
def draw(self):
892-
_no_output_draw(self.figure)
892+
self.figure.draw_no_output()
893893
return super().draw()
894894

895895

lib/matplotlib/backends/backend_ps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from matplotlib.afm import AFM
2424
from matplotlib.backend_bases import (
2525
_Backend, _check_savefig_extra_args, FigureCanvasBase, FigureManagerBase,
26-
GraphicsContextBase, RendererBase, _no_output_draw)
26+
GraphicsContextBase, RendererBase)
2727
from matplotlib.cbook import is_writable_file_like, file_requires_unicode
2828
from matplotlib.font_manager import get_font
2929
from matplotlib.ft2font import LOAD_NO_HINTING, LOAD_NO_SCALE
@@ -1112,7 +1112,7 @@ def _print_figure_tex(
11121112
_move_path_to_path_or_stream(tmpfile, outfile)
11131113

11141114
def draw(self):
1115-
_no_output_draw(self.figure)
1115+
self.figure.draw_no_output()
11161116
return super().draw()
11171117

11181118

lib/matplotlib/backends/backend_svg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from matplotlib import _api, cbook
1818
from matplotlib.backend_bases import (
1919
_Backend, _check_savefig_extra_args, FigureCanvasBase, FigureManagerBase,
20-
RendererBase, _no_output_draw)
20+
RendererBase)
2121
from matplotlib.backends.backend_mixed import MixedModeRenderer
2222
from matplotlib.colors import rgb2hex
2323
from matplotlib.dates import UTC
@@ -1343,7 +1343,7 @@ def get_default_filetype(self):
13431343
return 'svg'
13441344

13451345
def draw(self):
1346-
_no_output_draw(self.figure)
1346+
self.figure.draw_no_output()
13471347
return super().draw()
13481348

13491349

lib/matplotlib/figure.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from matplotlib.artist import (
2727
Artist, allow_rasterization, _finalize_rasterization)
2828
from matplotlib.backend_bases import (
29-
FigureCanvasBase, NonGuiException, MouseButton, _no_output_draw)
29+
FigureCanvasBase, NonGuiException, MouseButton, _get_renderer)
3030
import matplotlib._api as _api
3131
import matplotlib.cbook as cbook
3232
import matplotlib.colorbar as cbar
@@ -2744,7 +2744,9 @@ def draw_no_output(self):
27442744
Draw the figure with no output. Useful to get the final size of
27452745
artists that require a draw before their size is known (e.g. text).
27462746
"""
2747-
_no_output_draw(self)
2747+
renderer = _get_renderer(self)
2748+
with renderer._draw_disabled():
2749+
self.draw(renderer)
27482750

27492751
def draw_artist(self, a):
27502752
"""
@@ -3022,7 +3024,6 @@ def execute_constrained_layout(self, renderer=None):
30223024
"""
30233025

30243026
from matplotlib._constrained_layout import do_constrained_layout
3025-
from matplotlib.tight_layout import get_renderer
30263027

30273028
_log.debug('Executing constrainedlayout')
30283029
if self._layoutgrid is None:
@@ -3040,7 +3041,7 @@ def execute_constrained_layout(self, renderer=None):
30403041
w_pad = w_pad / width
30413042
h_pad = h_pad / height
30423043
if renderer is None:
3043-
renderer = get_renderer(fig)
3044+
renderer = _get_renderer(fig)
30443045
do_constrained_layout(fig, renderer, h_pad, w_pad, hspace, wspace)
30453046

30463047
def tight_layout(self, *, pad=1.08, h_pad=None, w_pad=None, rect=None):
@@ -3070,15 +3071,15 @@ def tight_layout(self, *, pad=1.08, h_pad=None, w_pad=None, rect=None):
30703071
"""
30713072

30723073
from .tight_layout import (
3073-
get_renderer, get_subplotspec_list, get_tight_layout_figure)
3074+
get_subplotspec_list, get_tight_layout_figure)
30743075
from contextlib import suppress
30753076
subplotspec_list = get_subplotspec_list(self.axes)
30763077
if None in subplotspec_list:
30773078
_api.warn_external("This figure includes Axes that are not "
30783079
"compatible with tight_layout, so results "
30793080
"might be incorrect.")
30803081

3081-
renderer = get_renderer(self)
3082+
renderer = _get_renderer(self)
30823083
ctx = (renderer._draw_disabled()
30833084
if hasattr(renderer, '_draw_disabled')
30843085
else suppress())

0 commit comments

Comments
 (0)