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

WIP: Don't draw_idle in non-GUI backends #5800

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

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion 2 lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,7 @@ def draw_idle(self, *args, **kwargs):
"""
:meth:`draw` only if idle; defaults to draw but backends can overrride
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps mention the interactive-only behavior in the docstring?

"""
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
67 changes: 41 additions & 26 deletions 67 lib/matplotlib/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ def test_contains():

# draw the text. This is important, as the contains method can only work
# when a renderer exists.
plt.draw()
plt.ion()
try:
plt.draw()
finally:
plt.ioff()

for x, y in zip(xs.flat, ys.flat):
mevent.x, mevent.y = plt.gca().transAxes.transform_point([x, y])
Expand Down Expand Up @@ -235,35 +239,40 @@ def test_axes_titles():

@cleanup
def test_set_position():
fig, ax = plt.subplots()
plt.ion()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a plt.ioff() call in the cleanup decorator?


try:
fig, ax = plt.subplots()

# test set_position
ann = ax.annotate(
'test', (0, 0), xytext=(0, 0), textcoords='figure pixels')
plt.draw()
# test set_position
ann = ax.annotate(
'test', (0, 0), xytext=(0, 0), textcoords='figure pixels')
plt.draw()

init_pos = ann.get_window_extent(fig.canvas.renderer)
shift_val = 15
ann.set_position((shift_val, shift_val))
plt.draw()
post_pos = ann.get_window_extent(fig.canvas.renderer)
init_pos = ann.get_window_extent(fig.canvas.renderer)
shift_val = 15
ann.set_position((shift_val, shift_val))
plt.draw()
post_pos = ann.get_window_extent(fig.canvas.renderer)

for a, b in zip(init_pos.min, post_pos.min):
assert a + shift_val == b
for a, b in zip(init_pos.min, post_pos.min):
assert a + shift_val == b

# test xyann
ann = ax.annotate(
'test', (0, 0), xytext=(0, 0), textcoords='figure pixels')
plt.draw()
# test xyann
ann = ax.annotate(
'test', (0, 0), xytext=(0, 0), textcoords='figure pixels')
plt.draw()

init_pos = ann.get_window_extent(fig.canvas.renderer)
shift_val = 15
ann.xyann = (shift_val, shift_val)
plt.draw()
post_pos = ann.get_window_extent(fig.canvas.renderer)
init_pos = ann.get_window_extent(fig.canvas.renderer)
shift_val = 15
ann.xyann = (shift_val, shift_val)
plt.draw()
post_pos = ann.get_window_extent(fig.canvas.renderer)

for a, b in zip(init_pos.min, post_pos.min):
assert a + shift_val == b
for a, b in zip(init_pos.min, post_pos.min):
assert a + shift_val == b
finally:
plt.ioff()


def test_get_rotation_string():
Expand Down Expand Up @@ -373,8 +382,14 @@ def test_annotation_negative_fig_coords():

@cleanup
def test_text_stale():
# A version of draw_all that draws even when interactive is off
def draw_all_when_not_interactive():
for f_mgr in plt._pylab_helpers.Gcf.get_all_fig_managers():
if f_mgr.canvas.figure.stale:
f_mgr.canvas.draw()

fig, (ax1, ax2) = plt.subplots(1, 2)
plt.draw_all()
draw_all_when_not_interactive()
assert not ax1.stale
assert not ax2.stale
assert not fig.stale
Expand All @@ -389,7 +404,7 @@ def test_text_stale():
assert ann1.stale
assert fig.stale

plt.draw_all()
draw_all_when_not_interactive()
assert not ax1.stale
assert not ax2.stale
assert not fig.stale
Morty Proxy This is a proxified and sanitized view of the page, visit original site.