matplotlib 具有额外列的表

p5cysglq  于 2023-05-29  发布在  其他
关注(0)|答案(1)|浏览(132)

我绘制了两个简单的表格,但两个表格上都出现了一个额外的列。我检查了我的数据只有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()
bvjxkvbb

bvjxkvbb1#

如果您删除rowColours,它将按预期工作

least_dev_tabel= axs[0].table(cellText=least_dev_values, colLabels=header, loc='center',
         cellLoc='center', colLoc='center', #rowColours=row_colors1,
         colColours=header_colors1)

看起来您可能希望根据标题向表中添加更多列?文档说这些是标题行的颜色。如果你想给你的单元格上色,你可以使用cellClours
https://matplotlib.org/stable/api/table_api.html

相关问题