我尝试了几种方法,但不知道如何正确地将文本集中在列中并收紧所有文本。
plt.close()
colors = []
for _, row in mail_decision_table.iterrows():
colors_in_column = ["aliceblue", "lightgrey"]
if row["Decision"]=="SELL":
colors_in_column[1] = "lightcoral"
else:
colors_in_column[1] = "lightgreen"
colors.append(colors_in_column)
fig, ax = plt.subplots()
ax.axis('tight')
ax.axis('off')
the_table = ax.table(cellText = mail_decision_table.values,
colLabels = mail_decision_table.columns,
loc='center',
rowLoc='center',
colColours = ["grey","grey"],
cellColours=colors)
for key, cell in the_table.get_celld().items():
cell.set_linewidth(0.5)
cell.set_linestyle("dashed")
cell.set_edgecolor("grey")
cell._loc = 'center'
if key[0] ==0 :
cell._text.set_color('white')
plt.show()
1条答案
按热度按时间c6ubokkw1#
将
cellLoc='center'
选项添加到the_table
变量: