简体   繁体   中英

Whitespace Around Table in Matplotlib

I want to create a table using Matplotlib to give the outcome of an engineering calculation. However, I can't get rid of the whitespace around the table. I want -almost- no whitespace around the table so user can copy the png and use it in their report.


import matplotlib.pyplot as plt
FS_VRM2002 = 1.4
FS_CTRS2013 = 1.3
FS_PSS2017 = 1.2
FS_A2012 = 1.1
FS_KLVF2017 = 1.0
FS_list = []
Name_list = []
if True:
    FS_list.append(FS_VRM2002)
    Name_list.append("Vermeer, Ruse & Marcher (2002)")
if True:
    FS_list.append(FS_CTRS2013)
    Name_list.append("Carranza-Torres et. al. (2013)")
if True:
    FS_list.append(FS_PSS2017)
    Name_list.append("Paternesi, Schweiger & Scarpelli (2017)  ")
if True:
    FS_list.append(FS_A2012)
    Name_list.append("Anagnostou (2012) ")
if True:
    FS_list.append(FS_KLVF2017)
    Name_list.append("Kavvadas, Litsas, Vazaios & Fortsakis (2017)")

FS_list_table = []
for i, j in enumerate(FS_list):
    FS_list_table.append([j])
    
fig, ax = plt.subplots(figsize=(6,5))


table = ax.table(
    cellText=FS_list_table,
    colLabels=["Factor of Safety"],
    rowLabels=Name_list,
    loc="center",
    cellLoc="center",
    colWidths=[0.2],
    rowLoc="center",
)
ax.axis("tight")
ax.axis("off")

Outcome:

在此处输入图像描述

You can reach a reproduced version here: https://share.streamlit.io/akrolsmir/streamlit-snippet/main?snippet_id=OEmnTTRC

If you want the whole figsize, specify it with box=[x0,x1,y0,y1] .

fig, ax = plt.subplots(figsize=(5,2.5))
table = ax.table(
    cellText=FS_list_table,
    colLabels=["Factor of Safety"],
    rowLabels=Name_list,
    loc="center",
    cellLoc="center",
    colWidths=[0.2],
    rowLoc="center",
    bbox=[0,0,1,1]
)
ax.axis("tight")
ax.axis("off")

plt.show()

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM