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

Skip to content

Commit b19ab83

Browse files
committed
Don't cache the renderer on the Axes instance.
The cache on the figure is sufficient.
1 parent 4769f7b commit b19ab83

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

examples/event_handling/pong_sgskip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def start_anim(event):
3636
canvas.mpl_disconnect(start_anim.cid)
3737

3838
def local_draw():
39-
if animation.ax._cachedRenderer:
39+
if animation.ax.get_renderer_cache():
4040
animation.draw(None)
4141
start_anim.timer.add_callback(local_draw)
4242
start_anim.timer.start()

lib/matplotlib/axes/_base.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,6 @@ def __init__(self, fig, rect,
486486
self.fmt_xdata = None
487487
self.fmt_ydata = None
488488

489-
self._cachedRenderer = None
490489
self.set_navigate(True)
491490
self.set_navigate_mode(None)
492491

@@ -542,7 +541,7 @@ def __getstate__(self):
542541
# The renderer should be re-created by the figure, and then cached at
543542
# that point.
544543
state = super().__getstate__()
545-
for key in ['_cachedRenderer', '_layoutbox', '_poslayoutbox']:
544+
for key in ['_layoutbox', '_poslayoutbox']:
546545
state[key] = None
547546
# Prune the sharing & twinning info to only contain the current group.
548547
for grouper_name in [
@@ -2510,7 +2509,7 @@ def _update_title_position(self, renderer):
25102509
def draw(self, renderer=None, inframe=False):
25112510
"""Draw everything (plot lines, axes, labels)"""
25122511
if renderer is None:
2513-
renderer = self._cachedRenderer
2512+
renderer = self.figure._cachedRenderer
25142513

25152514
if renderer is None:
25162515
raise RuntimeError('No renderer defined')
@@ -2581,7 +2580,6 @@ def draw(self, renderer=None, inframe=False):
25812580
mimage._draw_list_compositing_images(renderer, self, artists)
25822581

25832582
renderer.close_group('axes')
2584-
self._cachedRenderer = renderer
25852583
self.stale = False
25862584

25872585
def draw_artist(self, a):
@@ -2590,24 +2588,24 @@ def draw_artist(self, a):
25902588
caches the renderer. It is used to efficiently update Axes
25912589
data (axis ticks, labels, etc are not updated)
25922590
"""
2593-
if self._cachedRenderer is None:
2591+
if self.figure._cachedRenderer is None:
25942592
raise AttributeError("draw_artist can only be used after an "
25952593
"initial draw which caches the renderer")
2596-
a.draw(self._cachedRenderer)
2594+
a.draw(self.figure._cachedRenderer)
25972595

25982596
def redraw_in_frame(self):
25992597
"""
26002598
This method can only be used after an initial draw which
26012599
caches the renderer. It is used to efficiently update Axes
26022600
data (axis ticks, labels, etc are not updated)
26032601
"""
2604-
if self._cachedRenderer is None:
2602+
if self.figure._cachedRenderer is None:
26052603
raise AttributeError("redraw_in_frame can only be used after an "
26062604
"initial draw which caches the renderer")
2607-
self.draw(self._cachedRenderer, inframe=True)
2605+
self.draw(self.figure._cachedRenderer, inframe=True)
26082606

26092607
def get_renderer_cache(self):
2610-
return self._cachedRenderer
2608+
return self.figure._cachedRenderer
26112609

26122610
# Axes rectangle characteristics
26132611

0 commit comments

Comments
 (0)