【问题标题】:How can i change the "box" height of matblolib subplot and get the height of a matplotlib table?如何更改 matplotlib 子图的“框”高度并获取 matplotlib 表的高度?
【发布时间】:2020-06-01 18:36:21
【问题描述】:
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) )

这就是我所说的'盒子:

【问题讨论】:

  • 我做到了,网站说:“感谢您的反馈!声望低于 15 人的投票会被记录下来,但不要更改公开显示的帖子得分。”

标签: python python-3.x matplotlib height subplot


【解决方案1】:

一种可能是相反的:用fig,ax = plt.subplots(1, 1, figsize = (5, 2.5)) 设置图形的大小,然后设置表格的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 了解更多信息。

【讨论】:

    猜你喜欢
    • 2015-05-20
    • 2010-11-16
    • 2015-05-28
    • 2019-01-22
    • 1970-01-01
    • 2016-10-12
    • 2012-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多