@@ -629,44 +629,77 @@ def test_anchored_cbar_position_using_specgrid():
629629 levels = [0 , 200 , 400 , 600 , 800 , 1000 , 1200 ]
630630 shrink = 0.5
631631 anchor_y = 0.3
632- # vertival
632+ # right
633633 fig , ax = plt .subplots ()
634634 cs = ax .contourf (data , levels = levels )
635635 cbar = plt .colorbar (
636636 cs , ax = ax , use_gridspec = True ,
637- orientation = 'vertical ' , anchor = (1 , anchor_y ), shrink = shrink )
637+ location = 'right ' , anchor = (1 , anchor_y ), shrink = shrink )
638638
639- # y1: the top of ax, y0: the bottom of ax, p0: the y postion of anchor
640- # cy1 : the top of colorbar ax, cy0: the bottom of colorbar ax
641- y1 = ax .get_position ().y1
642- y0 = ax .get_position ().y0
639+ # the bottom left corner of one ax is (x0, y0)
640+ # the top right corner of one ax is (x1, y1)
641+ # p0: the verticle / horizontal postion of anchor
642+ x0 , y0 , x1 , y1 = ax .get_position ().extents
643+ cx0 , cy0 , cx1 , cy1 = cbar .ax .get_position ().extents
643644 p0 = (y1 - y0 ) * anchor_y + y0
644- cy1 = cbar .ax .get_position ().y1
645- cy0 = cbar .ax .get_position ().y0
646645
647646 np .testing .assert_allclose (
648647 [cy1 , cy0 ],
649- [y1 * shrink + (1 - shrink ) * p0 , p0 * (1 - shrink ) + y0 * shrink ]
650- )
648+ [y1 * shrink + (1 - shrink ) * p0 , p0 * (1 - shrink ) + y0 * shrink ])
651649
652- # horizontal
650+ # left
651+ fig , ax = plt .subplots ()
652+ cs = ax .contourf (data , levels = levels )
653+ cbar = plt .colorbar (
654+ cs , ax = ax , use_gridspec = True ,
655+ location = 'left' , anchor = (1 , anchor_y ), shrink = shrink )
656+
657+ # the bottom left corner of one ax is (x0, y0)
658+ # the top right corner of one ax is (x1, y1)
659+ # p0: the verticle / horizontal postion of anchor
660+ x0 , y0 , x1 , y1 = ax .get_position ().extents
661+ cx0 , cy0 , cx1 , cy1 = cbar .ax .get_position ().extents
662+ p0 = (y1 - y0 ) * anchor_y + y0
663+
664+ np .testing .assert_allclose (
665+ [cy1 , cy0 ],
666+ [y1 * shrink + (1 - shrink ) * p0 , p0 * (1 - shrink ) + y0 * shrink ])
667+ # top
668+ shrink = 0.5
669+ anchor_x = 0.3
670+ fig , ax = plt .subplots ()
671+ cs = ax .contourf (data , levels = levels )
672+ cbar = plt .colorbar (
673+ cs , ax = ax , use_gridspec = True ,
674+ location = 'top' , anchor = (anchor_x , 1 ), shrink = shrink )
675+
676+ # the bottom left corner of one ax is (x0, y0)
677+ # the top right corner of one ax is (x1, y1)
678+ # p0: the verticle / horizontal postion of anchor
679+ x0 , y0 , x1 , y1 = ax .get_position ().extents
680+ cx0 , cy0 , cx1 , cy1 = cbar .ax .get_position ().extents
681+ p0 = (x1 - x0 ) * anchor_x + x0
682+
683+ np .testing .assert_allclose (
684+ [cx1 , cx0 ],
685+ [x1 * shrink + (1 - shrink ) * p0 , p0 * (1 - shrink ) + x0 * shrink ])
686+
687+ # bottom
653688 shrink = 0.5
654689 anchor_x = 0.3
655690 fig , ax = plt .subplots ()
656691 cs = ax .contourf (data , levels = levels )
657692 cbar = plt .colorbar (
658693 cs , ax = ax , use_gridspec = True ,
659- orientation = 'horizontal ' , anchor = (anchor_x , 1 ), shrink = shrink )
694+ location = 'bottom ' , anchor = (anchor_x , 1 ), shrink = shrink )
660695
661- # x1: the right of ax, x0: the left of ax, p0: the x postion of anchor
662- # cx1 : the right of colorbar ax, cx0: the left of colorbar ax
663- x1 = ax .get_position ().x1
664- x0 = ax .get_position ().x0
696+ # the bottom left corner of one ax is (x0, y0)
697+ # the top right corner of one ax is (x1, y1)
698+ # p0: the verticle / horizontal postion of anchor
699+ x0 , y0 , x1 , y1 = ax .get_position ().extents
700+ cx0 , cy0 , cx1 , cy1 = cbar .ax .get_position ().extents
665701 p0 = (x1 - x0 ) * anchor_x + x0
666- cx1 = cbar .ax .get_position ().x1
667- cx0 = cbar .ax .get_position ().x0
668702
669703 np .testing .assert_allclose (
670704 [cx1 , cx0 ],
671- [x1 * shrink + (1 - shrink ) * p0 , p0 * (1 - shrink ) + x0 * shrink ]
672- )
705+ [x1 * shrink + (1 - shrink ) * p0 , p0 * (1 - shrink ) + x0 * shrink ])
0 commit comments