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

Skip to content

Commit ce85159

Browse files
committed
Use fig.canvas.draw() instead of plt.draw() in tests.
This allows one to copy-paste the test and use an interactive backend, while maintaining the test result. (Specifically, when using an interactive backend, plt.draw will *not* set the renderer until plt.show, whereas fig.canvas.draw will set it, allowing text extents to be measured.)
1 parent e1fd994 commit ce85159

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/matplotlib/tests/test_text.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def test_contains():
174174

175175
# draw the text. This is important, as the contains method can only work
176176
# when a renderer exists.
177-
plt.draw()
177+
fig.canvas.draw()
178178

179179
for x, y in zip(xs.flat, ys.flat):
180180
mevent.x, mevent.y = plt.gca().transAxes.transform_point([x, y])
@@ -238,12 +238,12 @@ def test_set_position():
238238
# test set_position
239239
ann = ax.annotate(
240240
'test', (0, 0), xytext=(0, 0), textcoords='figure pixels')
241-
plt.draw()
241+
fig.canvas.draw()
242242

243243
init_pos = ann.get_window_extent(fig.canvas.renderer)
244244
shift_val = 15
245245
ann.set_position((shift_val, shift_val))
246-
plt.draw()
246+
fig.canvas.draw()
247247
post_pos = ann.get_window_extent(fig.canvas.renderer)
248248

249249
for a, b in zip(init_pos.min, post_pos.min):
@@ -252,12 +252,12 @@ def test_set_position():
252252
# test xyann
253253
ann = ax.annotate(
254254
'test', (0, 0), xytext=(0, 0), textcoords='figure pixels')
255-
plt.draw()
255+
fig.canvas.draw()
256256

257257
init_pos = ann.get_window_extent(fig.canvas.renderer)
258258
shift_val = 15
259259
ann.xyann = (shift_val, shift_val)
260-
plt.draw()
260+
fig.canvas.draw()
261261
post_pos = ann.get_window_extent(fig.canvas.renderer)
262262

263263
for a, b in zip(init_pos.min, post_pos.min):

0 commit comments

Comments
 (0)