我想将数字与每个单元格的左上角对齐。我能够找到
set_text_props
,但它没有按照我的预期进行对齐。
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot()
ax.axis('off')
table = ax.table(
cellText=[[1, 2, 3, 4, 5, 6, 7],
[8, 9, 10, 11, 12, 13, 14]],
loc='center',
cellLoc='left',
)
table.set_fontsize(10)
table.scale(1, 4)
for (row, col), cell in table.get_celld().items():
cell.set_text_props(va='bottom')
(这是一个黑客,不是解决方案)
在文本中添加换行符并调整
cell.PAD
。
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(4,3))
ax = fig.add_subplot()
ax.axis('off')
cellText=[[1, 2, 3, 4, 5, 6, 7],
[8, 9, 10, 11, 12, 13, 14]]
for i in range(len(cellText)):
for j in range(len(cellText[i])):
cellText[i][j] = f"{cellText[i][j]}\n"
table = ax.table(
cellText=cellText,
loc='center',
cellLoc='left',
)
table.set_fontsize(10)
table.scale(1, 4)
for (row, col), cell in table.get_celld().items():
cell.set_text_props(va='bottom')
cell.PAD=0.05