33from mpl_toolkits .axes_grid1 .axes_divider import HBoxDivider
44import mpl_toolkits .axes_grid1 .axes_size as Size
55
6- def make_heights_equal (fig , ax1 , ax2 , pad ):
6+ def make_heights_equal (fig , rect , ax1 , ax2 , pad ):
77 # pad in inches
88
99 h1 , v1 = Size .AxesX (ax1 ), Size .AxesY (ax1 )
@@ -12,7 +12,7 @@ def make_heights_equal(fig, ax1, ax2, pad):
1212 pad_v = Size .Scaled (1 )
1313 pad_h = Size .Fixed (pad )
1414
15- my_divider = HBoxDivider (fig , 111 ,
15+ my_divider = HBoxDivider (fig , rect ,
1616 horizontal = [h1 , pad_h , h2 ],
1717 vertical = [v1 , pad_v , v2 ])
1818
@@ -33,8 +33,9 @@ def make_heights_equal(fig, ax1, ax2, pad):
3333
3434 ax1 .imshow (arr1 , interpolation = "nearest" )
3535 ax2 .imshow (arr2 , interpolation = "nearest" )
36-
37- make_heights_equal (fig1 , ax1 , ax2 , pad = 0.5 )
36+
37+ rect = 111 # subplot param for combined axes
38+ make_heights_equal (fig1 , rect , ax1 , ax2 , pad = 0.5 ) # pad in inches
3839
3940 for ax in [ax1 , ax2 ]:
4041 ax .locator_params (nbins = 4 )
@@ -43,6 +44,9 @@ def make_heights_equal(fig, ax1, ax2, pad):
4344 ax3 = plt .axes ([0.5 , 0.5 , 0.001 , 0.001 ], frameon = False )
4445 ax3 .xaxis .set_visible (False )
4546 ax3 .yaxis .set_visible (False )
46- ax3 .annotate ("Location of two axes are adjusted\n so that they have an equal height \n while maintaining their aspect ratios" , (0.5 , 0.5 ),
47+ ax3 .annotate ("Location of two axes are adjusted\n so that they have equal heights \n while maintaining their aspect ratios" , (0.5 , 0.5 ),
4748 xycoords = "axes fraction" , va = "center" , ha = "center" ,
48- bbox = dict (fc = "w" ))
49+ bbox = dict (boxstyle = "round, pad=1" , fc = "w" ))
50+
51+ plt .show ()
52+
0 commit comments