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

Skip to content

Commit 97a9bf7

Browse files
authored
Merge pull request #11689 from anntzer/dont-cache-renderer-on-axes
Don't cache the renderer on the Axes instance.
2 parents 6fcc530 + b19ab83 commit 97a9bf7

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 [
@@ -2533,7 +2532,7 @@ def _update_title_position(self, renderer):
25332532
def draw(self, renderer=None, inframe=False):
25342533
"""Draw everything (plot lines, axes, labels)"""
25352534
if renderer is None:
2536-
renderer = self._cachedRenderer
2535+
renderer = self.figure._cachedRenderer
25372536

25382537
if renderer is None:
25392538
raise RuntimeError('No renderer defined')
@@ -2604,7 +2603,6 @@ def draw(self, renderer=None, inframe=False):
26042603
mimage._draw_list_compositing_images(renderer, self, artists)
26052604

26062605
renderer.close_group('axes')
2607-
self._cachedRenderer = renderer
26082606
self.stale = False
26092607

26102608
def draw_artist(self, a):
@@ -2613,24 +2611,24 @@ def draw_artist(self, a):
26132611
caches the renderer. It is used to efficiently update Axes
26142612
data (axis ticks, labels, etc are not updated)
26152613
"""
2616-
if self._cachedRenderer is None:
2614+
if self.figure._cachedRenderer is None:
26172615
raise AttributeError("draw_artist can only be used after an "
26182616
"initial draw which caches the renderer")
2619-
a.draw(self._cachedRenderer)
2617+
a.draw(self.figure._cachedRenderer)
26202618

26212619
def redraw_in_frame(self):
26222620
"""
26232621
This method can only be used after an initial draw which
26242622
caches the renderer. It is used to efficiently update Axes
26252623
data (axis ticks, labels, etc are not updated)
26262624
"""
2627-
if self._cachedRenderer is None:
2625+
if self.figure._cachedRenderer is None:
26282626
raise AttributeError("redraw_in_frame can only be used after an "
26292627
"initial draw which caches the renderer")
2630-
self.draw(self._cachedRenderer, inframe=True)
2628+
self.draw(self.figure._cachedRenderer, inframe=True)
26312629

26322630
def get_renderer_cache(self):
2633-
return self._cachedRenderer
2631+
return self.figure._cachedRenderer
26342632

26352633
# Axes rectangle characteristics
26362634

0 commit comments

Comments
 (0)