如何更改 matplotlib 子图的 "box" 高度并获取 matplotlib table 的高度?

How can i change the "box" height of matblolib subplot and get the height of a matplotlib table?

import matplotlib.pyplot as plt
import pandas as pd
df= pd.DataFrame({'A':['a','b'],'B':[1,2],'C':[1,2]})
fig,ax = plt.subplots()
ax.set_title("title")
ax.set_xlabel('label')
plt.xticks([])
plt.yticks([])
tab = ax.table(rowLabels=range(1,3),colLabels=['A','B','C'],cellText=df.values,loc='center',rowLoc='center')
plt.show()
##My doubt:
function_that_resize_the_box_height( function_that_get_the_table_height(tab) )

这就是我所说的“盒子”的意思:

一种可能是相反的:用fig,ax = plt.subplots(1, 1, figsize = (5, 2.5))设置图形的大小,然后设置table的bbox参数,使其填满图形:

import matplotlib.pyplot as plt
import pandas as pd

df= pd.DataFrame({'A':['a','b'],'B':[1,2],'C':[1,2]})

fig,ax = plt.subplots(1, 1, figsize = (5, 2.5))
ax.set_title("title")
ax.set_xlabel('label')
plt.xticks([])
plt.yticks([])

tab = ax.table(rowLabels=range(1,3),colLabels=['A','B','C'],cellText=df.values,loc='center',rowLoc='center',
               bbox = [0, 0, 1, 1])

plt.show()

这是我得到的:

Check this 了解更多信息。