@@ -284,7 +284,7 @@ def test_colorbar_ticks():
284
284
colors = ['r' , 'g' , 'b' , 'c' ]
285
285
cs = ax .contourf (X , Y , Z , clevs , colors = colors , extend = 'neither' )
286
286
cbar = fig .colorbar (cs , ax = ax , orientation = 'horizontal' , ticks = clevs )
287
- assert len (cbar .ax . xaxis .get_ticklocs ()) == len (clevs )
287
+ assert len (cbar .xaxis .get_ticklocs ()) == len (clevs )
288
288
289
289
290
290
def test_colorbar_minorticks_on_off ():
@@ -301,17 +301,17 @@ def test_colorbar_minorticks_on_off():
301
301
# testing after minorticks_on()
302
302
cbar .minorticks_on ()
303
303
np .testing .assert_almost_equal (
304
- cbar .ax . yaxis .get_minorticklocs (),
304
+ cbar .yaxis .get_minorticklocs (),
305
305
[- 2.2 , - 1.8 , - 1.6 , - 1.4 , - 1.2 , - 0.8 , - 0.6 , - 0.4 , - 0.2 ,
306
306
0.2 , 0.4 , 0.6 , 0.8 , 1.2 , 1.4 , 1.6 , 1.8 , 2.2 , 2.4 , 2.6 , 2.8 , 3.2 ])
307
307
# testing after minorticks_off()
308
308
cbar .minorticks_off ()
309
- np .testing .assert_almost_equal (cbar .ax . yaxis .get_minorticklocs (), [])
309
+ np .testing .assert_almost_equal (cbar .yaxis .get_minorticklocs (), [])
310
310
311
311
im .set_clim (vmin = - 1.2 , vmax = 1.2 )
312
312
cbar .minorticks_on ()
313
313
np .testing .assert_almost_equal (
314
- cbar .ax . yaxis .get_minorticklocs (),
314
+ cbar .yaxis .get_minorticklocs (),
315
315
[- 1.1 , - 0.9 , - 0.8 , - 0.7 , - 0.6 , - 0.4 , - 0.3 , - 0.2 , - 0.1 ,
316
316
0.1 , 0.2 , 0.3 , 0.4 , 0.6 , 0.7 , 0.8 , 0.9 , 1.1 , 1.2 , 1.3 ])
317
317
@@ -322,20 +322,20 @@ def test_colorbar_minorticks_on_off():
322
322
im = ax .pcolormesh (data , norm = LogNorm ())
323
323
cbar = fig .colorbar (im )
324
324
fig .canvas .draw ()
325
- default_minorticklocks = cbar .ax . yaxis .get_minorticklocs ()
325
+ default_minorticklocks = cbar .yaxis .get_minorticklocs ()
326
326
# test that minorticks turn off for LogNorm
327
327
cbar .minorticks_off ()
328
- np .testing .assert_equal (cbar .ax . yaxis .get_minorticklocs (), [])
328
+ np .testing .assert_equal (cbar .yaxis .get_minorticklocs (), [])
329
329
330
330
# test that minorticks turn back on for LogNorm
331
331
cbar .minorticks_on ()
332
- np .testing .assert_equal (cbar .ax . yaxis .get_minorticklocs (),
332
+ np .testing .assert_equal (cbar .yaxis .get_minorticklocs (),
333
333
default_minorticklocks )
334
334
335
335
# test issue #13339: minorticks for LogNorm should stay off
336
336
cbar .minorticks_off ()
337
337
cbar .set_ticks ([3 , 5 , 7 , 9 ])
338
- np .testing .assert_equal (cbar .ax . yaxis .get_minorticklocs (), [])
338
+ np .testing .assert_equal (cbar .yaxis .get_minorticklocs (), [])
339
339
340
340
341
341
def test_cbar_minorticks_for_rc_xyminortickvisible ():
@@ -358,12 +358,12 @@ def test_cbar_minorticks_for_rc_xyminortickvisible():
358
358
im = ax .pcolormesh ([[1 , 2 ]], vmin = vmin , vmax = vmax )
359
359
360
360
cbar = fig .colorbar (im , extend = 'both' , orientation = 'vertical' )
361
- assert cbar .ax . yaxis .get_minorticklocs ()[0 ] >= vmin
362
- assert cbar .ax . yaxis .get_minorticklocs ()[- 1 ] <= vmax
361
+ assert cbar .yaxis .get_minorticklocs ()[0 ] >= vmin
362
+ assert cbar .yaxis .get_minorticklocs ()[- 1 ] <= vmax
363
363
364
364
cbar = fig .colorbar (im , extend = 'both' , orientation = 'horizontal' )
365
- assert cbar .ax . xaxis .get_minorticklocs ()[0 ] >= vmin
366
- assert cbar .ax . xaxis .get_minorticklocs ()[- 1 ] <= vmax
365
+ assert cbar .xaxis .get_minorticklocs ()[0 ] >= vmin
366
+ assert cbar .xaxis .get_minorticklocs ()[- 1 ] <= vmax
367
367
368
368
369
369
def test_colorbar_autoticks ():
@@ -384,7 +384,7 @@ def test_colorbar_autoticks():
384
384
cbar2 = fig .colorbar (pcm , ax = ax [1 ], extend = 'both' ,
385
385
orientation = 'vertical' , shrink = 0.4 )
386
386
# note only -10 to 10 are visible,
387
- np .testing .assert_almost_equal (cbar .ax . yaxis .get_ticklocs (),
387
+ np .testing .assert_almost_equal (cbar .yaxis .get_ticklocs (),
388
388
np .arange (- 15 , 16 , 5 ))
389
389
# note only -10 to 10 are visible
390
390
np .testing .assert_almost_equal (cbar2 .ax .yaxis .get_ticklocs (),
@@ -408,7 +408,7 @@ def test_colorbar_autotickslog():
408
408
cbar2 = fig .colorbar (pcm , ax = ax [1 ], extend = 'both' ,
409
409
orientation = 'vertical' , shrink = 0.4 )
410
410
# note only -12 to +12 are visible
411
- np .testing .assert_almost_equal (cbar .ax . yaxis .get_ticklocs (),
411
+ np .testing .assert_almost_equal (cbar .yaxis .get_ticklocs (),
412
412
10 ** np .arange (- 16. , 16.2 , 4. ))
413
413
# note only -24 to +24 are visible
414
414
np .testing .assert_almost_equal (cbar2 .ax .yaxis .get_ticklocs (),
@@ -488,7 +488,7 @@ def test_colorbar_log_minortick_labels():
488
488
pcm = ax .imshow ([[10000 , 50000 ]], norm = LogNorm ())
489
489
cb = fig .colorbar (pcm )
490
490
fig .canvas .draw ()
491
- lb = [l .get_text () for l in cb .ax . yaxis .get_ticklabels (which = 'both' )]
491
+ lb = [l .get_text () for l in cb .yaxis .get_ticklabels (which = 'both' )]
492
492
expected = [r'$\mathdefault{10^{4}}$' ,
493
493
r'$\mathdefault{2\times10^{4}}$' ,
494
494
r'$\mathdefault{3\times10^{4}}$' ,
@@ -504,21 +504,21 @@ def test_colorbar_renorm():
504
504
fig , ax = plt .subplots ()
505
505
im = ax .imshow (z )
506
506
cbar = fig .colorbar (im )
507
- np .testing .assert_allclose (cbar .ax . yaxis .get_majorticklocs (),
507
+ np .testing .assert_allclose (cbar .yaxis .get_majorticklocs (),
508
508
np .arange (0 , 120000.1 , 20000 ))
509
509
510
510
cbar .set_ticks ([1 , 2 , 3 ])
511
511
assert isinstance (cbar .locator , FixedLocator )
512
512
513
513
norm = LogNorm (z .min (), z .max ())
514
514
im .set_norm (norm )
515
- np .testing .assert_allclose (cbar .ax . yaxis .get_majorticklocs (),
515
+ np .testing .assert_allclose (cbar .yaxis .get_majorticklocs (),
516
516
np .logspace (- 10 , 7 , 18 ))
517
517
# note that set_norm removes the FixedLocator...
518
518
assert np .isclose (cbar .vmin , z .min ())
519
519
cbar .set_ticks ([1 , 2 , 3 ])
520
520
assert isinstance (cbar .locator , FixedLocator )
521
- np .testing .assert_allclose (cbar .ax . yaxis .get_majorticklocs (),
521
+ np .testing .assert_allclose (cbar .yaxis .get_majorticklocs (),
522
522
[1.0 , 2.0 , 3.0 ])
523
523
524
524
norm = LogNorm (z .min () * 1000 , z .max () * 1000 )
@@ -536,18 +536,18 @@ def test_colorbar_format():
536
536
im = ax .imshow (z )
537
537
cbar = fig .colorbar (im , format = '%4.2e' )
538
538
fig .canvas .draw ()
539
- assert cbar .ax . yaxis .get_ticklabels ()[4 ].get_text () == '8.00e+04'
539
+ assert cbar .yaxis .get_ticklabels ()[4 ].get_text () == '8.00e+04'
540
540
541
541
# make sure that if we change the clim of the mappable that the
542
542
# formatting is *not* lost:
543
543
im .set_clim ([4 , 200 ])
544
544
fig .canvas .draw ()
545
- assert cbar .ax . yaxis .get_ticklabels ()[4 ].get_text () == '2.00e+02'
545
+ assert cbar .yaxis .get_ticklabels ()[4 ].get_text () == '2.00e+02'
546
546
547
547
# but if we change the norm:
548
548
im .set_norm (LogNorm (vmin = 0.1 , vmax = 10 ))
549
549
fig .canvas .draw ()
550
- assert (cbar .ax . yaxis .get_ticklabels ()[0 ].get_text () ==
550
+ assert (cbar .yaxis .get_ticklabels ()[0 ].get_text () ==
551
551
r'$\mathdefault{10^{-2}}$' )
552
552
553
553
@@ -559,12 +559,12 @@ def test_colorbar_scale_reset():
559
559
pcm = ax .pcolormesh (z , cmap = 'RdBu_r' , rasterized = True )
560
560
cbar = fig .colorbar (pcm , ax = ax )
561
561
cbar .outline .set_edgecolor ('red' )
562
- assert cbar .ax . yaxis .get_scale () == 'linear'
562
+ assert cbar .yaxis .get_scale () == 'linear'
563
563
564
564
pcm .set_norm (LogNorm (vmin = 1 , vmax = 100 ))
565
- assert cbar .ax . yaxis .get_scale () == 'log'
565
+ assert cbar .yaxis .get_scale () == 'log'
566
566
pcm .set_norm (Normalize (vmin = - 20 , vmax = 20 ))
567
- assert cbar .ax . yaxis .get_scale () == 'linear'
567
+ assert cbar .yaxis .get_scale () == 'linear'
568
568
569
569
assert cbar .outline .get_edgecolor () == mcolors .to_rgba ('red' )
570
570
@@ -583,7 +583,7 @@ def test_colorbar_inverted_ticks():
583
583
pc = ax .pcolormesh (10 ** np .arange (1 , 5 ).reshape (2 , 2 ), norm = LogNorm ())
584
584
cbar = fig .colorbar (pc , ax = ax , extend = 'both' )
585
585
ticks = cbar .get_ticks ()
586
- cbar .ax . invert_yaxis ()
586
+ cbar .invert_yaxis ()
587
587
np .testing .assert_allclose (ticks , cbar .get_ticks ())
588
588
589
589
ax = axs [1 ]
@@ -592,7 +592,7 @@ def test_colorbar_inverted_ticks():
592
592
cbar .minorticks_on ()
593
593
ticks = cbar .get_ticks ()
594
594
minorticks = cbar .get_ticks (minor = True )
595
- cbar .ax . invert_yaxis ()
595
+ cbar .invert_yaxis ()
596
596
np .testing .assert_allclose (ticks , cbar .get_ticks ())
597
597
np .testing .assert_allclose (minorticks , cbar .get_ticks (minor = True ))
598
598
@@ -603,7 +603,7 @@ def test_extend_colorbar_customnorm():
603
603
fig , (ax0 , ax1 ) = plt .subplots (2 , 1 )
604
604
pcm = ax0 .pcolormesh ([[0 ]], norm = TwoSlopeNorm (vcenter = 0. , vmin = - 2 , vmax = 1 ))
605
605
cb = fig .colorbar (pcm , ax = ax0 , extend = 'both' )
606
- np .testing .assert_allclose (cb .ax . get_position ().extents ,
606
+ np .testing .assert_allclose (cb .get_position ().extents ,
607
607
[0.78375 , 0.536364 , 0.796147 , 0.9 ], rtol = 2e-3 )
608
608
609
609
@@ -623,11 +623,11 @@ def test_colorbar_label():
623
623
fig , ax = plt .subplots ()
624
624
im = ax .imshow ([[1 , 2 ], [3 , 4 ]])
625
625
cbar = fig .colorbar (im , label = 'cbar' )
626
- assert cbar .ax . get_ylabel () == 'cbar'
626
+ assert cbar .get_ylabel () == 'cbar'
627
627
cbar .set_label (None )
628
- assert cbar .ax . get_ylabel () == ''
628
+ assert cbar .get_ylabel () == ''
629
629
cbar .set_label ('cbar 2' )
630
- assert cbar .ax . get_ylabel () == 'cbar 2'
630
+ assert cbar .get_ylabel () == 'cbar 2'
631
631
632
632
cbar2 = fig .colorbar (im , label = None )
633
633
assert cbar2 .ax .get_ylabel () == ''
@@ -663,7 +663,7 @@ def test_anchored_cbar_position_using_specgrid():
663
663
# the top right corner of one ax is (x1, y1)
664
664
# p0: the vertical / horizontal position of anchor
665
665
x0 , y0 , x1 , y1 = ax .get_position ().extents
666
- cx0 , cy0 , cx1 , cy1 = cbar .ax . get_position ().extents
666
+ cx0 , cy0 , cx1 , cy1 = cbar .get_position ().extents
667
667
p0 = (y1 - y0 ) * anchor_y + y0
668
668
669
669
np .testing .assert_allclose (
@@ -681,7 +681,7 @@ def test_anchored_cbar_position_using_specgrid():
681
681
# the top right corner of one ax is (x1, y1)
682
682
# p0: the vertical / horizontal position of anchor
683
683
x0 , y0 , x1 , y1 = ax .get_position ().extents
684
- cx0 , cy0 , cx1 , cy1 = cbar .ax . get_position ().extents
684
+ cx0 , cy0 , cx1 , cy1 = cbar .get_position ().extents
685
685
p0 = (y1 - y0 ) * anchor_y + y0
686
686
687
687
np .testing .assert_allclose (
@@ -701,7 +701,7 @@ def test_anchored_cbar_position_using_specgrid():
701
701
# the top right corner of one ax is (x1, y1)
702
702
# p0: the vertical / horizontal position of anchor
703
703
x0 , y0 , x1 , y1 = ax .get_position ().extents
704
- cx0 , cy0 , cx1 , cy1 = cbar .ax . get_position ().extents
704
+ cx0 , cy0 , cx1 , cy1 = cbar .get_position ().extents
705
705
p0 = (x1 - x0 ) * anchor_x + x0
706
706
707
707
np .testing .assert_allclose (
@@ -721,7 +721,7 @@ def test_anchored_cbar_position_using_specgrid():
721
721
# the top right corner of one ax is (x1, y1)
722
722
# p0: the vertical / horizontal position of anchor
723
723
x0 , y0 , x1 , y1 = ax .get_position ().extents
724
- cx0 , cy0 , cx1 , cy1 = cbar .ax . get_position ().extents
724
+ cx0 , cy0 , cx1 , cy1 = cbar .get_position ().extents
725
725
p0 = (x1 - x0 ) * anchor_x + x0
726
726
727
727
np .testing .assert_allclose (
@@ -735,16 +735,16 @@ def test_colorbar_change_lim_scale():
735
735
fig , ax = plt .subplots (1 , 2 , constrained_layout = True )
736
736
pc = ax [0 ].pcolormesh (np .arange (100 ).reshape (10 , 10 )+ 1 )
737
737
cb = fig .colorbar (pc , ax = ax [0 ], extend = 'both' )
738
- cb .ax . set_yscale ('log' )
738
+ cb .set_yscale ('log' )
739
739
740
740
pc = ax [1 ].pcolormesh (np .arange (100 ).reshape (10 , 10 )+ 1 )
741
741
cb = fig .colorbar (pc , ax = ax [1 ], extend = 'both' )
742
- cb .ax . set_ylim ([20 , 90 ])
742
+ cb .set_ylim ([20 , 90 ])
743
743
744
744
745
745
@check_figures_equal (extensions = ["png" ])
746
746
def test_axes_handles_same_functions (fig_ref , fig_test ):
747
- # prove that cax and cb.ax are functionally the same
747
+ # prove that cax and cb are functionally the same
748
748
for nn , fig in enumerate ([fig_ref , fig_test ]):
749
749
ax = fig .add_subplot ()
750
750
pc = ax .pcolormesh (np .ones (300 ).reshape (10 , 30 ))
@@ -753,7 +753,7 @@ def test_axes_handles_same_functions(fig_ref, fig_test):
753
753
if nn == 0 :
754
754
caxx = cax
755
755
else :
756
- caxx = cb . ax
756
+ caxx = cb
757
757
caxx .set_yticks (np .arange (20 ))
758
758
caxx .set_yscale ('log' )
759
759
caxx .set_position ([0.92 , 0.1 , 0.02 , 0.7 ])
@@ -768,6 +768,6 @@ def test_inset_colorbar_layout():
768
768
fig .draw_no_output ()
769
769
# make sure this is in the figure. In the colorbar swapping
770
770
# it was being dropped from the list of children...
771
- np .testing .assert_allclose (cb .ax . get_position ().bounds ,
771
+ np .testing .assert_allclose (cb .get_position ().bounds ,
772
772
[0.87 , 0.342 , 0.0237 , 0.315 ], atol = 0.01 )
773
- assert cb .ax . outer_ax in ax .child_axes
773
+ assert cb .outer_ax in ax .child_axes
0 commit comments