Skip to content

FIX: set internal flags first in FigureCanvasBase #5150

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 7 commits into from
Sep 27, 2015
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
6 changes: 4 additions & 2 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,8 @@ class FigureCanvasBase(object):
'Tagged Image File Format')

def __init__(self, figure):
self._is_idle_drawing = True
self._is_saving = False
figure.set_canvas(self)
self.figure = figure
# a dictionary from event name to a dictionary that maps cid->func
Expand All @@ -1690,7 +1692,6 @@ def __init__(self, figure):
self.scroll_pick_id = self.mpl_connect('scroll_event', self.pick)
self.mouse_grabber = None # the axes currently grabbing mouse
self.toolbar = None # NavigationToolbar2 will set me
self._is_saving = False
self._is_idle_drawing = False

@contextmanager
Expand Down Expand Up @@ -2122,6 +2123,8 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
tight bbox is calculated.

"""
self._is_saving = True

if format is None:
# get format from filename, or from backend's default filetype
if cbook.is_string_like(filename):
Expand Down Expand Up @@ -2215,7 +2218,6 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
else:
_bbox_inches_restore = None

self._is_saving = True
try:
#result = getattr(self, method_name)(
result = print_method(
Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,6 @@ def set_canvas(self, canvas):
ACCEPTS: a FigureCanvas instance
"""
self.canvas = canvas
self.stale = True

def hold(self, b=None):
"""
Expand Down
24 changes: 9 additions & 15 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def _auto_draw_if_interactive(fig, val):
fig : Figure
A figure object which is assumed to be associated with a canvas
"""
if val and matplotlib.is_interactive():
if val and matplotlib.is_interactive() and not fig.canvas.is_saving():
fig.canvas.draw_idle()


Expand Down Expand Up @@ -666,33 +666,27 @@ def clf():


def draw():
"""
Redraw the current figure.
"""Redraw the current figure.

This is used in interactive mode to update a figure that
has been altered using one or more plot object method calls;
it is not needed if figure modification is done entirely
with pyplot functions, if a sequence of modifications ends
with a pyplot function, or if matplotlib is in non-interactive
mode and the sequence of modifications ends with :func:`show` or
:func:`savefig`.
This is used in interactive mode to update a figure that has been
altered, but not automatically re-drawn. This should be only rarely
needed, but there may be ways to modify the state of a figure with
out marking it as `stale`. Please report these cases as bugs.

A more object-oriented alternative, given any
:class:`~matplotlib.figure.Figure` instance, :attr:`fig`, that
was created using a :mod:`~matplotlib.pyplot` function, is::

fig.canvas.draw()


fig.canvas.draw_idle()
"""
get_current_fig_manager().canvas.draw()
get_current_fig_manager().canvas.draw_idle()


@docstring.copy_dedent(Figure.savefig)
def savefig(*args, **kwargs):
fig = gcf()
res = fig.savefig(*args, **kwargs)
draw() # need this if 'transparent=True' to reset colors
fig.canvas.draw_idle() # need this if 'transparent=True' to reset colors
return res


Expand Down
11 changes: 5 additions & 6 deletions lib/matplotlib/tests/test_backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,19 @@


def _test_savefig_to_stringio(format='ps', use_log=False):
fig, ax = plt.subplots()
buffers = [
six.moves.StringIO(),
io.StringIO(),
io.BytesIO()]

plt.figure()

if use_log:
plt.yscale('log')
ax.set_yscale('log')

plt.plot([1, 2], [1, 2])
plt.title("Déjà vu")
ax.plot([1, 2], [1, 2])
ax.set_title("Déjà vu")
for buffer in buffers:
plt.savefig(buffer, format=format)
fig.savefig(buffer, format=format)

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

Expand Down