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

Skip to content

Commit 0037595

Browse files
committed
Merge pull request #5150 from tacaswell/fix_draw_idle_again
FIX: set internal flags first in FigureCanvasBase
2 parents 87c9e4d + 0d465ac commit 0037595

File tree

4 files changed

+18
-24
lines changed

4 files changed

+18
-24
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,8 @@ class FigureCanvasBase(object):
16781678
'Tagged Image File Format')
16791679

16801680
def __init__(self, figure):
1681+
self._is_idle_drawing = True
1682+
self._is_saving = False
16811683
figure.set_canvas(self)
16821684
self.figure = figure
16831685
# a dictionary from event name to a dictionary that maps cid->func
@@ -1690,7 +1692,6 @@ def __init__(self, figure):
16901692
self.scroll_pick_id = self.mpl_connect('scroll_event', self.pick)
16911693
self.mouse_grabber = None # the axes currently grabbing mouse
16921694
self.toolbar = None # NavigationToolbar2 will set me
1693-
self._is_saving = False
16941695
self._is_idle_drawing = False
16951696

16961697
@contextmanager
@@ -2122,6 +2123,8 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
21222123
tight bbox is calculated.
21232124
21242125
"""
2126+
self._is_saving = True
2127+
21252128
if format is None:
21262129
# get format from filename, or from backend's default filetype
21272130
if cbook.is_string_like(filename):
@@ -2215,7 +2218,6 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
22152218
else:
22162219
_bbox_inches_restore = None
22172220

2218-
self._is_saving = True
22192221
try:
22202222
#result = getattr(self, method_name)(
22212223
result = print_method(

lib/matplotlib/figure.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,6 @@ def set_canvas(self, canvas):
560560
ACCEPTS: a FigureCanvas instance
561561
"""
562562
self.canvas = canvas
563-
self.stale = True
564563

565564
def hold(self, b=None):
566565
"""

lib/matplotlib/pyplot.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ def _auto_draw_if_interactive(fig, val):
564564
fig : Figure
565565
A figure object which is assumed to be associated with a canvas
566566
"""
567-
if val and matplotlib.is_interactive():
567+
if val and matplotlib.is_interactive() and not fig.canvas.is_saving():
568568
fig.canvas.draw_idle()
569569

570570

@@ -666,33 +666,27 @@ def clf():
666666

667667

668668
def draw():
669-
"""
670-
Redraw the current figure.
669+
"""Redraw the current figure.
671670
672-
This is used in interactive mode to update a figure that
673-
has been altered using one or more plot object method calls;
674-
it is not needed if figure modification is done entirely
675-
with pyplot functions, if a sequence of modifications ends
676-
with a pyplot function, or if matplotlib is in non-interactive
677-
mode and the sequence of modifications ends with :func:`show` or
678-
:func:`savefig`.
671+
This is used in interactive mode to update a figure that has been
672+
altered, but not automatically re-drawn. This should be only rarely
673+
needed, but there may be ways to modify the state of a figure with
674+
out marking it as `stale`. Please report these cases as bugs.
679675
680676
A more object-oriented alternative, given any
681677
:class:`~matplotlib.figure.Figure` instance, :attr:`fig`, that
682678
was created using a :mod:`~matplotlib.pyplot` function, is::
683679
684-
fig.canvas.draw()
685-
686-
680+
fig.canvas.draw_idle()
687681
"""
688-
get_current_fig_manager().canvas.draw()
682+
get_current_fig_manager().canvas.draw_idle()
689683

690684

691685
@docstring.copy_dedent(Figure.savefig)
692686
def savefig(*args, **kwargs):
693687
fig = gcf()
694688
res = fig.savefig(*args, **kwargs)
695-
draw() # need this if 'transparent=True' to reset colors
689+
fig.canvas.draw_idle() # need this if 'transparent=True' to reset colors
696690
return res
697691

698692

lib/matplotlib/tests/test_backend_ps.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,19 @@
2424

2525

2626
def _test_savefig_to_stringio(format='ps', use_log=False):
27+
fig, ax = plt.subplots()
2728
buffers = [
2829
six.moves.StringIO(),
2930
io.StringIO(),
3031
io.BytesIO()]
3132

32-
plt.figure()
33-
3433
if use_log:
35-
plt.yscale('log')
34+
ax.set_yscale('log')
3635

37-
plt.plot([1, 2], [1, 2])
38-
plt.title("Déjà vu")
36+
ax.plot([1, 2], [1, 2])
37+
ax.set_title("Déjà vu")
3938
for buffer in buffers:
40-
plt.savefig(buffer, format=format)
39+
fig.savefig(buffer, format=format)
4140

4241
values = [x.getvalue() for x in buffers]
4342

0 commit comments

Comments
 (0)