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

Commit 7924d7e

Browse filesBrowse files
committed
TST: convert almost all fig.canvas.draw -> fig.draw_no_output
This is probably a bad idea
1 parent 5bf1af0 commit 7924d7e
Copy full SHA for 7924d7e
Expand file treeCollapse file tree

28 files changed

+150
-146
lines changed

‎lib/matplotlib/tests/test_agg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_agg.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,13 @@ def test_chunksize():
208208
# Test without chunksize
209209
fig, ax = plt.subplots()
210210
ax.plot(x, np.sin(x))
211-
fig.canvas.draw()
211+
fig.draw_no_output()
212212

213213
# Test with chunksize
214214
fig, ax = plt.subplots()
215215
rcParams['agg.path.chunksize'] = 105
216216
ax.plot(x, np.sin(x))
217-
fig.canvas.draw()
217+
fig.draw_no_output()
218218

219219

220220
@pytest.mark.backend('Agg')
@@ -250,4 +250,5 @@ def test_draw_path_collection_error_handling():
250250
fig, ax = plt.subplots()
251251
ax.scatter([1], [1]).set_paths(path.Path([(0, 1), (2, 3)]))
252252
with pytest.raises(TypeError):
253+
# this needs to exercise code in the render paths
253254
fig.canvas.draw()

‎lib/matplotlib/tests/test_animation.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_animation.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,9 @@ def animate(i):
357357
else:
358358
return return_value
359359

360-
anim = animation.FuncAnimation(fig, animate, blit=True)
361-
fig.canvas.draw()
362-
360+
with pytest.raises(RuntimeError):
361+
anim = animation.FuncAnimation(fig, animate, blit=True)
362+
fig.draw_no_output()
363363

364364
def test_exhausted_animation(tmpdir):
365365
fig, ax = plt.subplots()

‎lib/matplotlib/tests/test_artist.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_artist.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def test_remove():
193193
assert fig.stale
194194
assert ax.stale
195195

196-
fig.canvas.draw()
196+
fig.draw_no_output()
197197
assert not fig.stale
198198
assert not ax.stale
199199
assert not ln.stale

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+43-43Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ def test_pcolor_regression(pd):
16731673

16741674
im = ax.pcolormesh(time_axis, y_axis, z_data)
16751675
# make sure this does not raise!
1676-
fig.canvas.draw()
1676+
fig.draw_no_output()
16771677
finally:
16781678
deregister_matplotlib_converters()
16791679

@@ -1759,7 +1759,7 @@ def test_hist_log_barstacked():
17591759
axs[0].set_yscale("log")
17601760
axs[1].hist([0, 0, 1], 2, histtype="barstacked")
17611761
axs[1].set_yscale("log")
1762-
fig.canvas.draw()
1762+
fig.draw_no_output()
17631763
assert axs[0].get_ylim() == axs[1].get_ylim()
17641764

17651765

@@ -3283,7 +3283,7 @@ def test_boxplot_not_single():
32833283
fig, ax = plt.subplots()
32843284
ax.boxplot(np.random.rand(100), positions=[3])
32853285
ax.boxplot(np.random.rand(100), positions=[5])
3286-
fig.canvas.draw()
3286+
fig.draw_no_output()
32873287
assert ax.get_xlim() == (2.5, 5.5)
32883288
assert list(ax.get_xticks()) == [3, 5]
32893289
assert [t.get_text() for t in ax.get_xticklabels()] == ["3", "5"]
@@ -4263,7 +4263,7 @@ def test_axline_args():
42634263
ax.set_yscale('linear')
42644264
with pytest.raises(ValueError):
42654265
ax.axline((0, 0), (0, 0)) # two identical points are not allowed
4266-
fig.canvas.draw()
4266+
fig.draw_no_output()
42674267

42684268

42694269
@image_comparison(['vlines_basic', 'vlines_with_nan', 'vlines_masked'],
@@ -4745,7 +4745,7 @@ def test_twin_spines_on_top():
47454745
def test_rcparam_grid_minor(grid_which, major_visible, minor_visible):
47464746
mpl.rcParams.update({"axes.grid": True, "axes.grid.which": grid_which})
47474747
fig, ax = plt.subplots()
4748-
fig.canvas.draw()
4748+
fig.draw_no_output()
47494749
assert all(tick.gridline.get_visible() == major_visible
47504750
for tick in ax.xaxis.majorTicks)
47514751
assert all(tick.gridline.get_visible() == minor_visible
@@ -4755,16 +4755,16 @@ def test_rcparam_grid_minor(grid_which, major_visible, minor_visible):
47554755
def test_grid():
47564756
fig, ax = plt.subplots()
47574757
ax.grid()
4758-
fig.canvas.draw()
4758+
fig.draw_no_output()
47594759
assert ax.xaxis.majorTicks[0].gridline.get_visible()
47604760
ax.grid(visible=False)
4761-
fig.canvas.draw()
4761+
fig.draw_no_output()
47624762
assert not ax.xaxis.majorTicks[0].gridline.get_visible()
47634763
ax.grid(visible=True)
4764-
fig.canvas.draw()
4764+
fig.draw_no_output()
47654765
assert ax.xaxis.majorTicks[0].gridline.get_visible()
47664766
ax.grid()
4767-
fig.canvas.draw()
4767+
fig.draw_no_output()
47684768
assert not ax.xaxis.majorTicks[0].gridline.get_visible()
47694769

47704770

@@ -4836,7 +4836,7 @@ def test_shared_with_aspect_2():
48364836
axs[0].set_aspect(2, share=True)
48374837
axs[0].plot([1, 2], [3, 4])
48384838
axs[1].plot([3, 4], [1, 2])
4839-
fig.canvas.draw()
4839+
fig.draw_no_output()
48404840
assert axs[0].get_xlim() == axs[1].get_xlim()
48414841
assert axs[0].get_ylim() == axs[1].get_ylim()
48424842

@@ -4849,7 +4849,7 @@ def test_shared_with_aspect_3():
48494849
axs[1].set_aspect(0.5, adjustable=adjustable)
48504850
axs[0].plot([1, 2], [3, 4])
48514851
axs[1].plot([3, 4], [1, 2])
4852-
fig.canvas.draw()
4852+
fig.draw_no_output()
48534853
assert axs[0].get_xlim() != axs[1].get_xlim()
48544854
assert axs[0].get_ylim() == axs[1].get_ylim()
48554855
fig_aspect = fig.bbox_inches.height / fig.bbox_inches.width
@@ -5151,7 +5151,7 @@ def test_subsampled_ticklabels():
51515151
ax.xaxis.set_ticks(np.arange(10) + 0.1)
51525152
ax.locator_params(nbins=5)
51535153
ax.xaxis.set_ticklabels([c for c in "bcdefghijk"])
5154-
fig.canvas.draw()
5154+
fig.draw_no_output()
51555155

51565156
labels = [t.get_text() for t in ax.xaxis.get_ticklabels()]
51575157
assert labels == ['b', 'd', 'f', 'h', 'j']
@@ -5307,22 +5307,22 @@ def test_move_offsetlabel():
53075307

53085308
fig, ax = plt.subplots()
53095309
ax.plot(data)
5310-
fig.canvas.draw()
5310+
fig.draw_no_output()
53115311
before = ax.yaxis.offsetText.get_position()
53125312
assert ax.yaxis.offsetText.get_horizontalalignment() == 'left'
53135313
ax.yaxis.tick_right()
5314-
fig.canvas.draw()
5314+
fig.draw_no_output()
53155315
after = ax.yaxis.offsetText.get_position()
53165316
assert after[0] > before[0] and after[1] == before[1]
53175317
assert ax.yaxis.offsetText.get_horizontalalignment() == 'right'
53185318

53195319
fig, ax = plt.subplots()
53205320
ax.plot(data)
5321-
fig.canvas.draw()
5321+
fig.draw_no_output()
53225322
before = ax.xaxis.offsetText.get_position()
53235323
assert ax.xaxis.offsetText.get_verticalalignment() == 'top'
53245324
ax.xaxis.tick_top()
5325-
fig.canvas.draw()
5325+
fig.draw_no_output()
53265326
after = ax.xaxis.offsetText.get_position()
53275327
assert after[0] == before[0] and after[1] > before[1]
53285328
assert ax.xaxis.offsetText.get_verticalalignment() == 'bottom'
@@ -5689,10 +5689,10 @@ def test_adjust_numtick_aspect():
56895689
ax.yaxis.get_major_locator().set_params(nbins='auto')
56905690
ax.set_xlim(0, 1000)
56915691
ax.set_aspect('equal')
5692-
fig.canvas.draw()
5692+
fig.draw_no_output()
56935693
assert len(ax.yaxis.get_major_locator()()) == 2
56945694
ax.set_ylim(0, 1000)
5695-
fig.canvas.draw()
5695+
fig.draw_no_output()
56965696
assert len(ax.yaxis.get_major_locator()()) > 2
56975697

56985698

@@ -5775,7 +5775,7 @@ def test_pandas_bar_align_center(pd):
57755775
df.loc[df['a'] == 1, 'b'],
57765776
align='center')
57775777

5778-
fig.canvas.draw()
5778+
fig.draw_no_output()
57795779

57805780

57815781
def test_tick_apply_tickdir_deprecation():
@@ -5941,7 +5941,7 @@ def test_titletwiny():
59415941
ax2 = ax.twiny()
59425942
xlabel2 = ax2.set_xlabel('Xlabel2')
59435943
title = ax.set_title('Title')
5944-
fig.canvas.draw()
5944+
fig.draw_no_output()
59455945
renderer = fig.canvas.get_renderer()
59465946
# ------- Test that title is put above Xlabel2 (Xlabel2 at top) ----------
59475947
bbox_y0_title = title.get_window_extent(renderer).y0 # bottom of title
@@ -5971,7 +5971,7 @@ def test_title_xticks_top():
59715971
fig, ax = plt.subplots()
59725972
ax.xaxis.set_ticks_position('top')
59735973
ax.set_title('xlabel top')
5974-
fig.canvas.draw()
5974+
fig.draw_no_output()
59755975
assert ax.title.get_position()[1] > 1.04
59765976

59775977

@@ -5982,7 +5982,7 @@ def test_title_xticks_top_both():
59825982
ax.tick_params(axis="x",
59835983
bottom=True, top=True, labelbottom=True, labeltop=True)
59845984
ax.set_title('xlabel top')
5985-
fig.canvas.draw()
5985+
fig.draw_no_output()
59865986
assert ax.title.get_position()[1] > 1.04
59875987

59885988

@@ -5995,7 +5995,7 @@ def test_title_no_move_off_page():
59955995
ax.tick_params(axis="x",
59965996
bottom=True, top=True, labelbottom=True, labeltop=True)
59975997
tt = ax.set_title('Boo')
5998-
fig.canvas.draw()
5998+
fig.draw_no_output()
59995999
assert tt.get_position()[1] == 1.0
60006000

60016001

@@ -6019,7 +6019,7 @@ def test_offset_text_visible():
60196019
def test_large_offset():
60206020
fig, ax = plt.subplots()
60216021
ax.plot((1 + np.array([0, 1.e-12])) * 1.e27)
6022-
fig.canvas.draw()
6022+
fig.draw_no_output()
60236023

60246024

60256025
def test_barb_units():
@@ -6241,7 +6241,7 @@ def test_inset():
62416241

62426242
rec, connectors = ax.indicate_inset(bounds=rect)
62436243
assert connectors is None
6244-
fig.canvas.draw()
6244+
fig.draw_no_output()
62456245
xx = np.array([[1.5, 2.],
62466246
[2.15, 2.5]])
62476247
assert np.all(rec.get_bbox().get_points() == xx)
@@ -6270,7 +6270,7 @@ def test_zoom_inset():
62706270

62716271
rec, connectors = ax.indicate_inset_zoom(axin1)
62726272
assert len(connectors) == 4
6273-
fig.canvas.draw()
6273+
fig.draw_no_output()
62746274
xx = np.array([[1.5, 2.],
62756275
[2.15, 2.5]])
62766276
assert np.all(rec.get_bbox().get_points() == xx)
@@ -6410,7 +6410,7 @@ def invert(x):
64106410
return 1 / x
64116411

64126412
ax.secondary_xaxis('top', functions=(invert, invert))
6413-
fig.canvas.draw()
6413+
fig.draw_no_output()
64146414
fig.set_size_inches((7, 4))
64156415
assert_allclose(ax.get_position().extents, [0.125, 0.1, 0.9, 0.9])
64166416

@@ -6430,11 +6430,11 @@ def invert(x):
64306430
assert isinstance(secax._axis.get_minor_locator(),
64316431
mticker.AutoMinorLocator)
64326432
ax.set_xscale('log')
6433-
fig.canvas.draw()
6433+
fig.draw_no_output()
64346434
assert isinstance(secax._axis.get_minor_locator(),
64356435
mticker.LogLocator)
64366436
ax.set_xscale('linear')
6437-
fig.canvas.draw()
6437+
fig.draw_no_output()
64386438
assert isinstance(secax._axis.get_minor_locator(),
64396439
mticker.NullLocator)
64406440

@@ -6444,7 +6444,7 @@ def test_secondary_formatter():
64446444
ax.set_xscale("log")
64456445
secax = ax.secondary_xaxis("top")
64466446
secax.xaxis.set_major_formatter(mticker.ScalarFormatter())
6447-
fig.canvas.draw()
6447+
fig.draw_no_output()
64486448
assert isinstance(
64496449
secax.xaxis.get_major_formatter(), mticker.ScalarFormatter)
64506450

@@ -6453,7 +6453,7 @@ def color_boxes(fig, ax):
64536453
"""
64546454
Helper for the tests below that test the extents of various axes elements
64556455
"""
6456-
fig.canvas.draw()
6456+
fig.draw_no_output()
64576457

64586458
renderer = fig.canvas.get_renderer()
64596459
bbaxis = []
@@ -6498,7 +6498,7 @@ def color_boxes(fig, ax):
64986498
def test_normal_axes():
64996499
with rc_context({'_internal.classic_mode': False}):
65006500
fig, ax = plt.subplots(dpi=200, figsize=(6, 6))
6501-
fig.canvas.draw()
6501+
fig.draw_no_output()
65026502
plt.close(fig)
65036503
bbaxis, bbspines, bbax, bbtb = color_boxes(fig, ax)
65046504

@@ -6537,7 +6537,7 @@ def test_normal_axes():
65376537
def test_nodecorator():
65386538
with rc_context({'_internal.classic_mode': False}):
65396539
fig, ax = plt.subplots(dpi=200, figsize=(6, 6))
6540-
fig.canvas.draw()
6540+
fig.draw_no_output()
65416541
ax.set(xticklabels=[], yticklabels=[])
65426542
bbaxis, bbspines, bbax, bbtb = color_boxes(fig, ax)
65436543

@@ -6569,7 +6569,7 @@ def test_displaced_spine():
65696569
fig, ax = plt.subplots(dpi=200, figsize=(6, 6))
65706570
ax.set(xticklabels=[], yticklabels=[])
65716571
ax.spines.bottom.set_position(('axes', -0.1))
6572-
fig.canvas.draw()
6572+
fig.draw_no_output()
65736573
bbaxis, bbspines, bbax, bbtb = color_boxes(fig, ax)
65746574

65756575
targets = [
@@ -6605,7 +6605,7 @@ def test_tickdirs():
66056605
with rc_context({'_internal.classic_mode': False}):
66066606
fig, ax = plt.subplots(dpi=200, figsize=(6, 6))
66076607
ax.tick_params(direction=dirs)
6608-
fig.canvas.draw()
6608+
fig.draw_no_output()
66096609
bbaxis, bbspines, bbax, bbtb = color_boxes(fig, ax)
66106610
for nn, num in enumerate([0, 2]):
66116611
targetbb = mtransforms.Bbox.from_bounds(*targets[dnum][nn])
@@ -6616,7 +6616,7 @@ def test_tickdirs():
66166616
def test_minor_accountedfor():
66176617
with rc_context({'_internal.classic_mode': False}):
66186618
fig, ax = plt.subplots(dpi=200, figsize=(6, 6))
6619-
fig.canvas.draw()
6619+
fig.draw_no_output()
66206620
ax.tick_params(which='both', direction='out')
66216621

66226622
bbaxis, bbspines, bbax, bbtb = color_boxes(fig, ax)
@@ -6629,11 +6629,11 @@ def test_minor_accountedfor():
66296629
bbspines[n * 2].bounds, targetbb.bounds, atol=1e-2)
66306630

66316631
fig, ax = plt.subplots(dpi=200, figsize=(6, 6))
6632-
fig.canvas.draw()
6632+
fig.draw_no_output()
66336633
ax.tick_params(which='both', direction='out')
66346634
ax.minorticks_on()
66356635
ax.tick_params(axis='both', which='minor', length=30)
6636-
fig.canvas.draw()
6636+
fig.draw_no_output()
66376637
bbaxis, bbspines, bbax, bbtb = color_boxes(fig, ax)
66386638
targets = [[150.0, 36.66666666666663, 930.0, 83.33333333333334],
66396639
[66.6667, 120.0, 83.3333, 960.0]]
@@ -6816,7 +6816,7 @@ def test_bbox_aspect_axes_init():
68166816
# all equal square axes.
68176817
fig, axs = plt.subplots(2, 3, subplot_kw=dict(box_aspect=1),
68186818
constrained_layout=True)
6819-
fig.canvas.draw()
6819+
fig.draw_no_output()
68206820
renderer = fig.canvas.get_renderer()
68216821
sizes = []
68226822
for ax in axs.flat:
@@ -6829,7 +6829,7 @@ def test_bbox_aspect_axes_init():
68296829
def test_redraw_in_frame():
68306830
fig, ax = plt.subplots(1, 1)
68316831
ax.plot([1, 2, 3])
6832-
fig.canvas.draw()
6832+
fig.draw_no_output()
68336833
ax.redraw_in_frame()
68346834

68356835

@@ -6873,7 +6873,7 @@ def test_unautoscale(axis, auto):
68736873

68746874
set_lim((-0.5, 0.5), auto=auto)
68756875
assert post_auto == get_autoscale_on()
6876-
fig.canvas.draw()
6876+
fig.draw_no_output()
68776877
assert_array_equal(get_lim(), (-0.5, 0.5))
68786878

68796879

@@ -6889,7 +6889,7 @@ def test_polar_interpolation_steps_variable_r(fig_test, fig_ref):
68896889
def test_autoscale_tiny_sticky():
68906890
fig, ax = plt.subplots()
68916891
ax.bar(0, 1e-9)
6892-
fig.canvas.draw()
6892+
fig.draw_no_output()
68936893
assert ax.get_ylim() == (0, 1.05e-9)
68946894

68956895

@@ -6920,7 +6920,7 @@ def test_relative_ticklabel_sizes(size):
69206920
mpl.rcParams['xtick.labelsize'] = size
69216921
mpl.rcParams['ytick.labelsize'] = size
69226922
fig, ax = plt.subplots()
6923-
fig.canvas.draw()
6923+
fig.draw_no_output()
69246924

69256925
for name, axis in zip(['x', 'y'], [ax.xaxis, ax.yaxis]):
69266926
for tick in axis.get_major_ticks():

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.