Issue
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.
I need to remove the cell edges, AND add the cell fill. Any help would be greatly appreciated.
Solution
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:
Answered By - BigBen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.