@@ -1673,7 +1673,7 @@ def test_pcolor_regression(pd):
1673
1673
1674
1674
im = ax .pcolormesh (time_axis , y_axis , z_data )
1675
1675
# make sure this does not raise!
1676
- fig .canvas . draw ()
1676
+ fig .draw_no_output ()
1677
1677
finally :
1678
1678
deregister_matplotlib_converters ()
1679
1679
@@ -1759,7 +1759,7 @@ def test_hist_log_barstacked():
1759
1759
axs [0 ].set_yscale ("log" )
1760
1760
axs [1 ].hist ([0 , 0 , 1 ], 2 , histtype = "barstacked" )
1761
1761
axs [1 ].set_yscale ("log" )
1762
- fig .canvas . draw ()
1762
+ fig .draw_no_output ()
1763
1763
assert axs [0 ].get_ylim () == axs [1 ].get_ylim ()
1764
1764
1765
1765
@@ -3283,7 +3283,7 @@ def test_boxplot_not_single():
3283
3283
fig , ax = plt .subplots ()
3284
3284
ax .boxplot (np .random .rand (100 ), positions = [3 ])
3285
3285
ax .boxplot (np .random .rand (100 ), positions = [5 ])
3286
- fig .canvas . draw ()
3286
+ fig .draw_no_output ()
3287
3287
assert ax .get_xlim () == (2.5 , 5.5 )
3288
3288
assert list (ax .get_xticks ()) == [3 , 5 ]
3289
3289
assert [t .get_text () for t in ax .get_xticklabels ()] == ["3" , "5" ]
@@ -4263,7 +4263,7 @@ def test_axline_args():
4263
4263
ax .set_yscale ('linear' )
4264
4264
with pytest .raises (ValueError ):
4265
4265
ax .axline ((0 , 0 ), (0 , 0 )) # two identical points are not allowed
4266
- fig .canvas . draw ()
4266
+ fig .draw_no_output ()
4267
4267
4268
4268
4269
4269
@image_comparison (['vlines_basic' , 'vlines_with_nan' , 'vlines_masked' ],
@@ -4745,7 +4745,7 @@ def test_twin_spines_on_top():
4745
4745
def test_rcparam_grid_minor (grid_which , major_visible , minor_visible ):
4746
4746
mpl .rcParams .update ({"axes.grid" : True , "axes.grid.which" : grid_which })
4747
4747
fig , ax = plt .subplots ()
4748
- fig .canvas . draw ()
4748
+ fig .draw_no_output ()
4749
4749
assert all (tick .gridline .get_visible () == major_visible
4750
4750
for tick in ax .xaxis .majorTicks )
4751
4751
assert all (tick .gridline .get_visible () == minor_visible
@@ -4755,16 +4755,16 @@ def test_rcparam_grid_minor(grid_which, major_visible, minor_visible):
4755
4755
def test_grid ():
4756
4756
fig , ax = plt .subplots ()
4757
4757
ax .grid ()
4758
- fig .canvas . draw ()
4758
+ fig .draw_no_output ()
4759
4759
assert ax .xaxis .majorTicks [0 ].gridline .get_visible ()
4760
4760
ax .grid (visible = False )
4761
- fig .canvas . draw ()
4761
+ fig .draw_no_output ()
4762
4762
assert not ax .xaxis .majorTicks [0 ].gridline .get_visible ()
4763
4763
ax .grid (visible = True )
4764
- fig .canvas . draw ()
4764
+ fig .draw_no_output ()
4765
4765
assert ax .xaxis .majorTicks [0 ].gridline .get_visible ()
4766
4766
ax .grid ()
4767
- fig .canvas . draw ()
4767
+ fig .draw_no_output ()
4768
4768
assert not ax .xaxis .majorTicks [0 ].gridline .get_visible ()
4769
4769
4770
4770
@@ -4836,7 +4836,7 @@ def test_shared_with_aspect_2():
4836
4836
axs [0 ].set_aspect (2 , share = True )
4837
4837
axs [0 ].plot ([1 , 2 ], [3 , 4 ])
4838
4838
axs [1 ].plot ([3 , 4 ], [1 , 2 ])
4839
- fig .canvas . draw ()
4839
+ fig .draw_no_output ()
4840
4840
assert axs [0 ].get_xlim () == axs [1 ].get_xlim ()
4841
4841
assert axs [0 ].get_ylim () == axs [1 ].get_ylim ()
4842
4842
@@ -4849,7 +4849,7 @@ def test_shared_with_aspect_3():
4849
4849
axs [1 ].set_aspect (0.5 , adjustable = adjustable )
4850
4850
axs [0 ].plot ([1 , 2 ], [3 , 4 ])
4851
4851
axs [1 ].plot ([3 , 4 ], [1 , 2 ])
4852
- fig .canvas . draw ()
4852
+ fig .draw_no_output ()
4853
4853
assert axs [0 ].get_xlim () != axs [1 ].get_xlim ()
4854
4854
assert axs [0 ].get_ylim () == axs [1 ].get_ylim ()
4855
4855
fig_aspect = fig .bbox_inches .height / fig .bbox_inches .width
@@ -5151,7 +5151,7 @@ def test_subsampled_ticklabels():
5151
5151
ax .xaxis .set_ticks (np .arange (10 ) + 0.1 )
5152
5152
ax .locator_params (nbins = 5 )
5153
5153
ax .xaxis .set_ticklabels ([c for c in "bcdefghijk" ])
5154
- fig .canvas . draw ()
5154
+ fig .draw_no_output ()
5155
5155
5156
5156
labels = [t .get_text () for t in ax .xaxis .get_ticklabels ()]
5157
5157
assert labels == ['b' , 'd' , 'f' , 'h' , 'j' ]
@@ -5307,22 +5307,22 @@ def test_move_offsetlabel():
5307
5307
5308
5308
fig , ax = plt .subplots ()
5309
5309
ax .plot (data )
5310
- fig .canvas . draw ()
5310
+ fig .draw_no_output ()
5311
5311
before = ax .yaxis .offsetText .get_position ()
5312
5312
assert ax .yaxis .offsetText .get_horizontalalignment () == 'left'
5313
5313
ax .yaxis .tick_right ()
5314
- fig .canvas . draw ()
5314
+ fig .draw_no_output ()
5315
5315
after = ax .yaxis .offsetText .get_position ()
5316
5316
assert after [0 ] > before [0 ] and after [1 ] == before [1 ]
5317
5317
assert ax .yaxis .offsetText .get_horizontalalignment () == 'right'
5318
5318
5319
5319
fig , ax = plt .subplots ()
5320
5320
ax .plot (data )
5321
- fig .canvas . draw ()
5321
+ fig .draw_no_output ()
5322
5322
before = ax .xaxis .offsetText .get_position ()
5323
5323
assert ax .xaxis .offsetText .get_verticalalignment () == 'top'
5324
5324
ax .xaxis .tick_top ()
5325
- fig .canvas . draw ()
5325
+ fig .draw_no_output ()
5326
5326
after = ax .xaxis .offsetText .get_position ()
5327
5327
assert after [0 ] == before [0 ] and after [1 ] > before [1 ]
5328
5328
assert ax .xaxis .offsetText .get_verticalalignment () == 'bottom'
@@ -5689,10 +5689,10 @@ def test_adjust_numtick_aspect():
5689
5689
ax .yaxis .get_major_locator ().set_params (nbins = 'auto' )
5690
5690
ax .set_xlim (0 , 1000 )
5691
5691
ax .set_aspect ('equal' )
5692
- fig .canvas . draw ()
5692
+ fig .draw_no_output ()
5693
5693
assert len (ax .yaxis .get_major_locator ()()) == 2
5694
5694
ax .set_ylim (0 , 1000 )
5695
- fig .canvas . draw ()
5695
+ fig .draw_no_output ()
5696
5696
assert len (ax .yaxis .get_major_locator ()()) > 2
5697
5697
5698
5698
@@ -5775,7 +5775,7 @@ def test_pandas_bar_align_center(pd):
5775
5775
df .loc [df ['a' ] == 1 , 'b' ],
5776
5776
align = 'center' )
5777
5777
5778
- fig .canvas . draw ()
5778
+ fig .draw_no_output ()
5779
5779
5780
5780
5781
5781
def test_tick_apply_tickdir_deprecation ():
@@ -5941,7 +5941,7 @@ def test_titletwiny():
5941
5941
ax2 = ax .twiny ()
5942
5942
xlabel2 = ax2 .set_xlabel ('Xlabel2' )
5943
5943
title = ax .set_title ('Title' )
5944
- fig .canvas . draw ()
5944
+ fig .draw_no_output ()
5945
5945
renderer = fig .canvas .get_renderer ()
5946
5946
# ------- Test that title is put above Xlabel2 (Xlabel2 at top) ----------
5947
5947
bbox_y0_title = title .get_window_extent (renderer ).y0 # bottom of title
@@ -5971,7 +5971,7 @@ def test_title_xticks_top():
5971
5971
fig , ax = plt .subplots ()
5972
5972
ax .xaxis .set_ticks_position ('top' )
5973
5973
ax .set_title ('xlabel top' )
5974
- fig .canvas . draw ()
5974
+ fig .draw_no_output ()
5975
5975
assert ax .title .get_position ()[1 ] > 1.04
5976
5976
5977
5977
@@ -5982,7 +5982,7 @@ def test_title_xticks_top_both():
5982
5982
ax .tick_params (axis = "x" ,
5983
5983
bottom = True , top = True , labelbottom = True , labeltop = True )
5984
5984
ax .set_title ('xlabel top' )
5985
- fig .canvas . draw ()
5985
+ fig .draw_no_output ()
5986
5986
assert ax .title .get_position ()[1 ] > 1.04
5987
5987
5988
5988
@@ -5995,7 +5995,7 @@ def test_title_no_move_off_page():
5995
5995
ax .tick_params (axis = "x" ,
5996
5996
bottom = True , top = True , labelbottom = True , labeltop = True )
5997
5997
tt = ax .set_title ('Boo' )
5998
- fig .canvas . draw ()
5998
+ fig .draw_no_output ()
5999
5999
assert tt .get_position ()[1 ] == 1.0
6000
6000
6001
6001
@@ -6019,7 +6019,7 @@ def test_offset_text_visible():
6019
6019
def test_large_offset ():
6020
6020
fig , ax = plt .subplots ()
6021
6021
ax .plot ((1 + np .array ([0 , 1.e-12 ])) * 1.e27 )
6022
- fig .canvas . draw ()
6022
+ fig .draw_no_output ()
6023
6023
6024
6024
6025
6025
def test_barb_units ():
@@ -6241,7 +6241,7 @@ def test_inset():
6241
6241
6242
6242
rec , connectors = ax .indicate_inset (bounds = rect )
6243
6243
assert connectors is None
6244
- fig .canvas . draw ()
6244
+ fig .draw_no_output ()
6245
6245
xx = np .array ([[1.5 , 2. ],
6246
6246
[2.15 , 2.5 ]])
6247
6247
assert np .all (rec .get_bbox ().get_points () == xx )
@@ -6270,7 +6270,7 @@ def test_zoom_inset():
6270
6270
6271
6271
rec , connectors = ax .indicate_inset_zoom (axin1 )
6272
6272
assert len (connectors ) == 4
6273
- fig .canvas . draw ()
6273
+ fig .draw_no_output ()
6274
6274
xx = np .array ([[1.5 , 2. ],
6275
6275
[2.15 , 2.5 ]])
6276
6276
assert np .all (rec .get_bbox ().get_points () == xx )
@@ -6410,7 +6410,7 @@ def invert(x):
6410
6410
return 1 / x
6411
6411
6412
6412
ax .secondary_xaxis ('top' , functions = (invert , invert ))
6413
- fig .canvas . draw ()
6413
+ fig .draw_no_output ()
6414
6414
fig .set_size_inches ((7 , 4 ))
6415
6415
assert_allclose (ax .get_position ().extents , [0.125 , 0.1 , 0.9 , 0.9 ])
6416
6416
@@ -6430,11 +6430,11 @@ def invert(x):
6430
6430
assert isinstance (secax ._axis .get_minor_locator (),
6431
6431
mticker .AutoMinorLocator )
6432
6432
ax .set_xscale ('log' )
6433
- fig .canvas . draw ()
6433
+ fig .draw_no_output ()
6434
6434
assert isinstance (secax ._axis .get_minor_locator (),
6435
6435
mticker .LogLocator )
6436
6436
ax .set_xscale ('linear' )
6437
- fig .canvas . draw ()
6437
+ fig .draw_no_output ()
6438
6438
assert isinstance (secax ._axis .get_minor_locator (),
6439
6439
mticker .NullLocator )
6440
6440
@@ -6444,7 +6444,7 @@ def test_secondary_formatter():
6444
6444
ax .set_xscale ("log" )
6445
6445
secax = ax .secondary_xaxis ("top" )
6446
6446
secax .xaxis .set_major_formatter (mticker .ScalarFormatter ())
6447
- fig .canvas . draw ()
6447
+ fig .draw_no_output ()
6448
6448
assert isinstance (
6449
6449
secax .xaxis .get_major_formatter (), mticker .ScalarFormatter )
6450
6450
@@ -6453,7 +6453,7 @@ def color_boxes(fig, ax):
6453
6453
"""
6454
6454
Helper for the tests below that test the extents of various axes elements
6455
6455
"""
6456
- fig .canvas . draw ()
6456
+ fig .draw_no_output ()
6457
6457
6458
6458
renderer = fig .canvas .get_renderer ()
6459
6459
bbaxis = []
@@ -6498,7 +6498,7 @@ def color_boxes(fig, ax):
6498
6498
def test_normal_axes ():
6499
6499
with rc_context ({'_internal.classic_mode' : False }):
6500
6500
fig , ax = plt .subplots (dpi = 200 , figsize = (6 , 6 ))
6501
- fig .canvas . draw ()
6501
+ fig .draw_no_output ()
6502
6502
plt .close (fig )
6503
6503
bbaxis , bbspines , bbax , bbtb = color_boxes (fig , ax )
6504
6504
@@ -6537,7 +6537,7 @@ def test_normal_axes():
6537
6537
def test_nodecorator ():
6538
6538
with rc_context ({'_internal.classic_mode' : False }):
6539
6539
fig , ax = plt .subplots (dpi = 200 , figsize = (6 , 6 ))
6540
- fig .canvas . draw ()
6540
+ fig .draw_no_output ()
6541
6541
ax .set (xticklabels = [], yticklabels = [])
6542
6542
bbaxis , bbspines , bbax , bbtb = color_boxes (fig , ax )
6543
6543
@@ -6569,7 +6569,7 @@ def test_displaced_spine():
6569
6569
fig , ax = plt .subplots (dpi = 200 , figsize = (6 , 6 ))
6570
6570
ax .set (xticklabels = [], yticklabels = [])
6571
6571
ax .spines .bottom .set_position (('axes' , - 0.1 ))
6572
- fig .canvas . draw ()
6572
+ fig .draw_no_output ()
6573
6573
bbaxis , bbspines , bbax , bbtb = color_boxes (fig , ax )
6574
6574
6575
6575
targets = [
@@ -6605,7 +6605,7 @@ def test_tickdirs():
6605
6605
with rc_context ({'_internal.classic_mode' : False }):
6606
6606
fig , ax = plt .subplots (dpi = 200 , figsize = (6 , 6 ))
6607
6607
ax .tick_params (direction = dirs )
6608
- fig .canvas . draw ()
6608
+ fig .draw_no_output ()
6609
6609
bbaxis , bbspines , bbax , bbtb = color_boxes (fig , ax )
6610
6610
for nn , num in enumerate ([0 , 2 ]):
6611
6611
targetbb = mtransforms .Bbox .from_bounds (* targets [dnum ][nn ])
@@ -6616,7 +6616,7 @@ def test_tickdirs():
6616
6616
def test_minor_accountedfor ():
6617
6617
with rc_context ({'_internal.classic_mode' : False }):
6618
6618
fig , ax = plt .subplots (dpi = 200 , figsize = (6 , 6 ))
6619
- fig .canvas . draw ()
6619
+ fig .draw_no_output ()
6620
6620
ax .tick_params (which = 'both' , direction = 'out' )
6621
6621
6622
6622
bbaxis , bbspines , bbax , bbtb = color_boxes (fig , ax )
@@ -6629,11 +6629,11 @@ def test_minor_accountedfor():
6629
6629
bbspines [n * 2 ].bounds , targetbb .bounds , atol = 1e-2 )
6630
6630
6631
6631
fig , ax = plt .subplots (dpi = 200 , figsize = (6 , 6 ))
6632
- fig .canvas . draw ()
6632
+ fig .draw_no_output ()
6633
6633
ax .tick_params (which = 'both' , direction = 'out' )
6634
6634
ax .minorticks_on ()
6635
6635
ax .tick_params (axis = 'both' , which = 'minor' , length = 30 )
6636
- fig .canvas . draw ()
6636
+ fig .draw_no_output ()
6637
6637
bbaxis , bbspines , bbax , bbtb = color_boxes (fig , ax )
6638
6638
targets = [[150.0 , 36.66666666666663 , 930.0 , 83.33333333333334 ],
6639
6639
[66.6667 , 120.0 , 83.3333 , 960.0 ]]
@@ -6816,7 +6816,7 @@ def test_bbox_aspect_axes_init():
6816
6816
# all equal square axes.
6817
6817
fig , axs = plt .subplots (2 , 3 , subplot_kw = dict (box_aspect = 1 ),
6818
6818
constrained_layout = True )
6819
- fig .canvas . draw ()
6819
+ fig .draw_no_output ()
6820
6820
renderer = fig .canvas .get_renderer ()
6821
6821
sizes = []
6822
6822
for ax in axs .flat :
@@ -6829,7 +6829,7 @@ def test_bbox_aspect_axes_init():
6829
6829
def test_redraw_in_frame ():
6830
6830
fig , ax = plt .subplots (1 , 1 )
6831
6831
ax .plot ([1 , 2 , 3 ])
6832
- fig .canvas . draw ()
6832
+ fig .draw_no_output ()
6833
6833
ax .redraw_in_frame ()
6834
6834
6835
6835
@@ -6873,7 +6873,7 @@ def test_unautoscale(axis, auto):
6873
6873
6874
6874
set_lim ((- 0.5 , 0.5 ), auto = auto )
6875
6875
assert post_auto == get_autoscale_on ()
6876
- fig .canvas . draw ()
6876
+ fig .draw_no_output ()
6877
6877
assert_array_equal (get_lim (), (- 0.5 , 0.5 ))
6878
6878
6879
6879
@@ -6889,7 +6889,7 @@ def test_polar_interpolation_steps_variable_r(fig_test, fig_ref):
6889
6889
def test_autoscale_tiny_sticky ():
6890
6890
fig , ax = plt .subplots ()
6891
6891
ax .bar (0 , 1e-9 )
6892
- fig .canvas . draw ()
6892
+ fig .draw_no_output ()
6893
6893
assert ax .get_ylim () == (0 , 1.05e-9 )
6894
6894
6895
6895
@@ -6920,7 +6920,7 @@ def test_relative_ticklabel_sizes(size):
6920
6920
mpl .rcParams ['xtick.labelsize' ] = size
6921
6921
mpl .rcParams ['ytick.labelsize' ] = size
6922
6922
fig , ax = plt .subplots ()
6923
- fig .canvas . draw ()
6923
+ fig .draw_no_output ()
6924
6924
6925
6925
for name , axis in zip (['x' , 'y' ], [ax .xaxis , ax .yaxis ]):
6926
6926
for tick in axis .get_major_ticks ():
0 commit comments