Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Dont double draw #17923

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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
Loading
from
Draft
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
20 changes: 20 additions & 0 deletions 20 doc/api/next_api_changes/behavior/17923-TAC.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Make ``draw_idle`` method on ``FigureCanvasBase`` a no-op if not in interactive mode
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For backends that do not have an event loop associated with them
(e.g. non-GUI backends) the semantics of `.FigureCanvasBase.draw_idle` are
not clear. Previously it was equivalent to a non-re-entrant
``fig.canvas.draw()`` call in all cases. Now it will be a no-op
unless Matplotlib is in "interactive mode" (as given by
`matplotlib.is_interactive`).

There are a number of derived properties in the Figure that we defer
computing until draw time (limits, ticks, the size of things in screen
space, optimized layout, etc). If you need to be sure that these
values are correct (with any backend) call ::

fig.draw_no_output()

to force the Figure to fully render. This may break user code if it
is relying on `pyplot.draw` (which internally calls ``draw_idle``)
for the same effect in non-interactive mode.
2 changes: 1 addition & 1 deletion 2 lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2054,7 +2054,7 @@ def draw_idle(self, *args, **kwargs):
strategy to prevent multiple renderings.

"""
if not self._is_idle_drawing:
if is_interactive() and not self._is_idle_drawing:
with self._idle_draw_cntx():
self.draw(*args, **kwargs)

Expand Down
5 changes: 3 additions & 2 deletions 5 lib/matplotlib/tests/test_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ def test_chunksize():
# Test without chunksize
fig, ax = plt.subplots()
ax.plot(x, np.sin(x))
fig.canvas.draw()
fig.draw_no_output()

# Test with chunksize
fig, ax = plt.subplots()
rcParams['agg.path.chunksize'] = 105
ax.plot(x, np.sin(x))
fig.canvas.draw()
fig.draw_no_output()


@pytest.mark.backend('Agg')
Expand Down Expand Up @@ -250,4 +250,5 @@ def test_draw_path_collection_error_handling():
fig, ax = plt.subplots()
ax.scatter([1], [1]).set_paths(path.Path([(0, 1), (2, 3)]))
with pytest.raises(TypeError):
# this needs to exercise code in the render paths
fig.canvas.draw()
3 changes: 2 additions & 1 deletion 3 lib/matplotlib/tests/test_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ def animate(i):
return return_value

with pytest.raises(RuntimeError):
animation.FuncAnimation(fig, animate, blit=True)
anim = animation.FuncAnimation(fig, animate, blit=True)
fig.draw_no_output()


def test_exhausted_animation(tmpdir):
Expand Down
2 changes: 1 addition & 1 deletion 2 lib/matplotlib/tests/test_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def test_remove():
assert fig.stale
assert ax.stale

fig.canvas.draw()
fig.draw_no_output()
assert not fig.stale
assert not ax.stale
assert not ln.stale
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.