baobobs
baobobs

Reputation: 703

Color fill table cells while also removing cell edges

This is seemingly very simple, but for some reason, I can either remove cell edges from a table, or fill the table cells with color, but not both. I'm using v3.4.2.

import matplotlib.pyplot as plt

values = [[1,2,3],[4,5,6],[7,8,9]]
columns = ['Column 1', 'Column 2', 'Column 3']
colors = [['y','y','y'],['w','w','w'],['y','y','y']]

fig, ax = plt.subplots()
fig.patch.set_visible(False)
ax.axis('off')
ax.axis('tight')

table = ax.table(cellText=values,
                colLabels=columns,
                cellColours=colors,
                edges='open',
                loc='center')
                        
plt.show()

Using the above code, the table edges are successfully hidden, but the cell colors do not appear. If I comment out edges='open', however, the cell colors appear, but of course the table edges remain present. enter image description here enter image description here

I need to remove the cell edges, AND add the cell fill. Any help would be greatly appreciated.

Upvotes: 1

Views: 975

Answers (1)

BigBen
BigBen

Reputation: 49998

There may be a better way than this, but one option is to explicitly set the edge color of all the Artists contained by the table to 'none'.

table = ax.table(cellText=values,
                colLabels=columns,
                cellColours=colors,
                loc='center')

for c in table.get_children():
    c.set_edgecolor('none')

Output:

enter image description here

Upvotes: 2

Related Questions