我绘制了两个简单的表格,但两个表格上都出现了一个额外的列。我检查了我的数据只有3列,colLabel也是如此。
from matplotlib import pyplot as plt
header= ['Country','HDI','IPV']
header_colors1 = ['#03a1fc', '#03a1fc', '#03a1fc']
row_colors1 = ['#f1f1f2', 'w'] * 10
header_colors2 = ['#dd8452', '#dd8452', '#dd8452']
row_colors2 = ['w', '#f1f1f2'] * 10
fig, axs = plt.subplots(1, 2, figsize=(8, 4))
fig.patch.set_visible(False)
axs[0].axis('off')
axs[0].axis('tight')
least_dev_values = [str(x) for x in range(10)]
most_dev_values = [str(x) for x in range(10)]
least_dev_tabel= axs[0].table(cellText=least_dev_values, colLabels=header, loc='center',
cellLoc='center', colLoc='center', rowColours=row_colors1,
colColours=header_colors1)
axs[1].axis('off')
axs[1].axis('tight')
axs[1].table(cellText=most_dev_values, colLabels=header, loc='center',
cellLoc='center', colLoc='center', rowColours=row_colors2,
colColours=header_colors2)
plt.subplots_adjust(wspace=0.8)
plt.show()
1条答案
按热度按时间bvjxkvbb1#
如果您删除rowColours,它将按预期工作
看起来您可能希望根据标题向表中添加更多列?文档说这些是标题行的颜色。如果你想给你的单元格上色,你可以使用
cellClours
https://matplotlib.org/stable/api/table_api.html